Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the certificate role to create the cert and the key #78

Merged
merged 2 commits into from
Nov 1, 2022

Conversation

nhosoi
Copy link
Contributor

@nhosoi nhosoi commented Oct 10, 2022

  • Introduce a variable cockpit_certificates to set the certificate_requests.
  • Add a test test script tests/tests_certificate2.yml

I borrowed (again :) the mssql README in linux-system-roles/mssql#125 written by @spetrosi. Thanks, Sergei!

@spetrosi, @martinpitt , this is another piece of the effort to use other roles in the cockpit role. If you could review it, I'd greatly appreciate it.

@nhosoi nhosoi changed the title Use the certificate role to create the cert and the key [WIP] Use the certificate role to create the cert and the key Oct 10, 2022
@nhosoi
Copy link
Contributor Author

nhosoi commented Oct 10, 2022

[citest]

README.md Outdated
You can also use the `certificate` role inside the `cockpit` role to create
certificates by providing `cockpit_certificates`.

Use this variable to generate certificate and private key for TLS encryption
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Use this variable to generate certificate and private key for TLS encryption
Use the `cockpit_certificates` variable to generate certificate and private key for TLS encryption

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @spetrosi!

@nhosoi
Copy link
Contributor Author

nhosoi commented Oct 11, 2022

[citest]

@nhosoi nhosoi changed the title [WIP] Use the certificate role to create the cert and the key Use the certificate role to create the cert and the key Oct 11, 2022
@nhosoi
Copy link
Contributor Author

nhosoi commented Oct 13, 2022

[citest pending]

@nhosoi
Copy link
Contributor Author

nhosoi commented Oct 14, 2022

@spetrosi, @martinpitt, all the CI tests have passed. Could you please review one more time? Thanks!

spetrosi
spetrosi previously approved these changes Oct 17, 2022
Copy link
Collaborator

@spetrosi spetrosi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@nhosoi
Copy link
Contributor Author

nhosoi commented Oct 17, 2022

Thanks a lot for your reviews, @spetrosi.
@martinpitt, could you please take another look? If it looks ok to you, may I ask you to merge this pr? Thanks, in advance.

Copy link
Collaborator

@martinpitt martinpitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I'd like to see just one approach, not two. I also have some grammar/style fixes for the documentation.

README.md Outdated
@@ -170,6 +172,35 @@ You can also use `ca: self-sign` or `ca: local` depending on your certmonger usa

Note that this does *not* work on RHEL/CentOS 7.

#### Generate a new certificate in the role
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find this a bit nicer, and our role retains more control over what actually happens. So 👍 from me for moving to that approach.

But please let's actually move -- I find it confusing to offer "you can do it like this or that" in the README. Which one is better? (from the admin's POV). IMHO we should recommend just one approach.

The setype: hack is indeed obsolete. RHEL 8.6 has Cockpit 264, and CentOS 8 has something much newer. So we don't need this any more, neither with the "builtin" role.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find this a bit nicer, and our role retains more control over what actually happens. So +1 from me for moving to that approach.

But please let's actually move -- I find it confusing to offer "you can do it like this or that" in the README. Which one is better? (from the admin's POV). IMHO we should recommend just one approach.

The setype: hack is indeed obsolete. RHEL 8.6 has Cockpit 264, and CentOS 8 has something much newer. So we don't need this any more, neither with the "builtin" role.

Hmmm, a good point... Maybe, we can say something like this?

### Generate a new certificate

Now you can do it in the cockpit role by providing the cockpit_certificates variable as follows
(in the nicer English, of course ;)
    - name: Install cockpit with Cockpit web server certificate
      include_role:
        name: linux-system-roles.cockpit
      vars:
        cockpit_certificates:
          - name: monger-cockpit
            dns: ['localhost', 'www.example.com']
            ca: ipa
            group: cockpit-ws

If you already have a playbook using the certificate role and the cockpit role separately,
that's supported, too.
    - name: Generate Cockpit web server certificate
      include_role:
        name: linux-system-roles.certificate
      vars:
        certificate_requests:
          - name: /etc/cockpit/ws-certs.d/monger-cockpit
            dns: ['localhost', 'www.example.com']
            ca: ipa
            group: cockpit-ws

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed -- documenting this new way as the primary method, and just giving this a fallback is fine.

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
tests/tests_certificate2.yml Outdated Show resolved Hide resolved
@nhosoi
Copy link
Contributor Author

nhosoi commented Oct 20, 2022

[citest]

@nhosoi
Copy link
Contributor Author

nhosoi commented Oct 20, 2022

Thanks a lot, @martinpitt. I've pushed a commit fixing the issues you found (I hope :).
Could you please take one more look at the latest commit? Thanks!

@nhosoi
Copy link
Contributor Author

nhosoi commented Oct 20, 2022

[citest]

martinpitt
martinpitt previously approved these changes Oct 21, 2022
Copy link
Collaborator

@martinpitt martinpitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@nhosoi
Copy link
Contributor Author

nhosoi commented Oct 21, 2022

[citest pending]

@nhosoi
Copy link
Contributor Author

nhosoi commented Oct 21, 2022

Thank you for your reviews and suggestions, @martinpitt and @spetrosi.
All the CI tests have passed.
If you have the privilege and merge this pr, I'd appreciate it. Thanks!

@nhosoi
Copy link
Contributor Author

nhosoi commented Oct 24, 2022

@richm, I'm adding your note to the cockpit README, as well.
Do you think my addition is appropriate?

- Introduce a variable cockpit_certificates to set the certificate_requests.
- Add a test script tests_certificate_internal.yml.
- Rename tests_certificate.yml to tests_certificate_external.yml.
- Update README so that using the certificate role is recommended.
@nhosoi
Copy link
Contributor Author

nhosoi commented Oct 25, 2022

[citest]

@nhosoi
Copy link
Contributor Author

nhosoi commented Oct 25, 2022

[citest pending]

@nhosoi
Copy link
Contributor Author

nhosoi commented Oct 25, 2022

I believe all the CI tests have passed.
This is a leftover from the old attempt...

RHEL-8.8.0-20221020.2/ansible-2.9/(citool) Pending — Test started

@richm, @martinpitt, could you please review one more time (if needed) and merge this pr? Thanks, in advance.

richm
richm previously approved these changes Oct 25, 2022
- name: Create certificates
when:
- cockpit_certificates | length > 0
- ansible_facts['os_family'] == 'RedHat'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The node in the readme says NOTE: This does *not* work on RHEL/CentOS 7. - do we need to add a condition for that e.g.

    - ansible_facts['distribution_version'] is version('>=', '8')

?

Copy link
Contributor Author

@nhosoi nhosoi Oct 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, sorry. The note is not needed. The issue was if we try to generate the new cert directly in the target location /etc/cockpit/ws-certs.d like this:

    cockpit_certificates:
      - name: /etc/cockpit/ws-certs.d/cockpit_cert
        <<snip>>

it fails due to this bug on RHEL/CentOS-7 with an invalid mode.

In this PR, it generates the private key and cert in the standard location and copies them to the directories Cockpit expects. So, it is free from the issue. And there's no problem running on RHEL/CentOS-7. (CI successfully passed on the platforms.) I'm removing the note. Thanks for finding it out, @richm!

Oops, the note is needed. It is for this example (located above in README), in which the full path /etc/cockpit/ws-certs.d/monger-cockpit is specified. THAT does not work on RHEL/CentOS 7.

    - name: Generate Cockpit web server certificate
      include_role:
        name: linux-system-roles.certificate
      vars:
        certificate_requests:
          - name: /etc/cockpit/ws-certs.d/monger-cockpit
            dns: ['localhost', 'www.example.com']
            ca: ipa
            group: cockpit-ws

Do we want to describe in a little more detailed manner something like this?

NOTE: This specifying the certificate location by full path does *not* work on RHEL/CentOS 7.

Copy link
Contributor

@richm richm Oct 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to describe in a little more detailed manner something like this?

Yes - and - do we have a bz or some other issue tracker for this issue? Or maybe it is a "feature" of cockpit/certmonger?

@nhosoi
Copy link
Contributor Author

nhosoi commented Oct 28, 2022

[citest]

@nhosoi
Copy link
Contributor Author

nhosoi commented Oct 28, 2022

Do we want to describe in a little more detailed manner something like this?

Yes - and - do we have a bz or some other issue tracker for this issue? Or maybe it is a "feature" of the cockpit/certmonger?

These 2 issues were filed by @martinpitt against RHEL/CentOS-7 last year, which are still open.
linux-system-roles/certificate#98
linux-system-roles/certificate#99

And as you suggested, I've added a condition - if the distribution is RedHat and the version is 7, and the ca is self-sign, it fails with an error Creating a self-signed certificate is not supported on RHEL-7 or CentOS-7.

tasks/main.yml Outdated
include_role:
name: fedora.linux_system_roles.certificate
vars:
__cert_name: "{{ cockpit_certificates.0.name | basename }}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is __cert_name used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @richm. Removed it.

@nhosoi
Copy link
Contributor Author

nhosoi commented Oct 29, 2022

[citest]

@richm richm merged commit 706a601 into linux-system-roles:master Nov 1, 2022
richm added a commit to richm/linux-system-roles-cockpit that referenced this pull request Nov 1, 2022
[1.4.0] - 2022-11-01
--------------------

### New Features

- Use the firewall role and the selinux role from the cockpit role (linux-system-roles#76)

Since cockpit_port is a public api of the cockpit role, define it
in defaults/main.yml as null.

- Introduce cockpit_manage_firewall to use the firewall role to
  manage the cockpit service.
  Default to false - means the firewall role is not used.

- Add the test check task tasks/check_port.yml for verifying the
  ports status.

- Add meta/collection-requirements.yml.

- Introduce cockpit_manage_selinux to use the selinux role to
  manage the ports in the cockpit service.
  Assign websm_port_t to the cockpit service ports.
  Default to false - means the selinux role is not used.

- Use the certificate role to create the cert and the key (linux-system-roles#78)

- Introduce a variable cockpit_certificates to set the certificate_requests.

- Update README so that using the certificate role is recommended.

Add a check and README note for not supporting creating a self-signed
certificate on RHEL/CentOS-7.

### Bug Fixes

- none

### Other Changes

- workflows: Add integration-tests for Ubuntu 22.04 (linux-system-roles#68)

The current LTS 22.04 is the more interesting target. This detects bugs
like [1]. Keep 20.04 running as well for the time being.

[1] linux-system-roles/certificate#130

- Clone the certificate role in the temporary dir. (linux-system-roles#77)

Signed-off-by: Rich Megginson <rmeggins@redhat.com>
richm added a commit that referenced this pull request Nov 2, 2022
[1.4.0] - 2022-11-01
--------------------

### New Features

- Use the firewall role and the selinux role from the cockpit role (#76)

Since cockpit_port is a public api of the cockpit role, define it
in defaults/main.yml as null.

- Introduce cockpit_manage_firewall to use the firewall role to
  manage the cockpit service.
  Default to false - means the firewall role is not used.

- Add the test check task tasks/check_port.yml for verifying the
  ports status.

- Add meta/collection-requirements.yml.

- Introduce cockpit_manage_selinux to use the selinux role to
  manage the ports in the cockpit service.
  Assign websm_port_t to the cockpit service ports.
  Default to false - means the selinux role is not used.

- Use the certificate role to create the cert and the key (#78)

- Introduce a variable cockpit_certificates to set the certificate_requests.

- Update README so that using the certificate role is recommended.

Add a check and README note for not supporting creating a self-signed
certificate on RHEL/CentOS-7.

### Bug Fixes

- none

### Other Changes

- workflows: Add integration-tests for Ubuntu 22.04 (#68)

The current LTS 22.04 is the more interesting target. This detects bugs
like [1]. Keep 20.04 running as well for the time being.

[1] linux-system-roles/certificate#130

- Clone the certificate role in the temporary dir. (#77)

Signed-off-by: Rich Megginson <rmeggins@redhat.com>

Signed-off-by: Rich Megginson <rmeggins@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants