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

Remove CSR from CS.cfg and store them in certs folder #4588

Merged
merged 3 commits into from
Oct 17, 2023

Conversation

fmarco76
Copy link
Member

CSR are created and stored in <instance_config>/certs folder as <certs_id>.csr files.

Fix #2111

@fmarco76 fmarco76 requested a review from edewata October 12, 2023 17:37
Copy link
Contributor

@edewata edewata left a comment

Choose a reason for hiding this comment

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

Please see my comments below.

base/server/upgrade/11.5.0/04-RemoveCertCSRfromConfig.py Outdated Show resolved Hide resolved
The parameters `<subsystem_name>.<cert_id>.cert` and `<subsystem_name>.<cert_id>.certreq` are removed from `CS.cfg` files.
Certificates are retrieved from the nssdb configured and they are not stored in other places.
CSR are stored in the folder `<instance_config>/certs` as `<cert_nickname>.csr` and they are retrieved from this location.
For the cloning operation CSRs have to be specified in `pkispawn` configuration because they cannot be retrieved from the master configuration.
Copy link
Contributor

Choose a reason for hiding this comment

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

This means if someone has an automation for the cloning process (e.g. QE, IPA) this change will break it. I think initially we should continue supporting the existing mechanism (i.e. retrieving the CSRs from master) but we can generate a warning saying that we're deprecating this process and they will need to provide the CSRs to pkispawn. Then in the future we can drop the old code.

We probably should also consider providing a tool to export the CSRs more easily, e.g. creating a tarball containing all CSRs so the admin doesn't need to deal with multiple files.

Copy link
Contributor

Choose a reason for hiding this comment

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

You might also want to update the IPA clone test to verify that the <instance>/certs/<nickname>.csr files exist on the clones.

Copy link
Member Author

Choose a reason for hiding this comment

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

@edewata I miss this last comment. I'll add before merge or when working on the CSR healtcheck test.

Comment on lines 1388 to 1404
tags = subsystem.config['preop.cert.list'].split(',')
for tag in tags:
if tag == 'sslserver':
continue

# check CSR in CS.cfg
param = '%s.%s.certreq' % (subsystem.name, tag)
csr = subsystem.config.get(param)

if csr:
# CSR already exists
continue

# CSR doesn't exist, import from master
names.append(param)

if subsystem.name == 'ca':
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this code needs to be restored, but instead of checking the <subsystem>.<tag>.certreq we should check the <instance>/certs/<nickname>.csr file. If the file exists we can skip it, but otherwise we need to import the CSR from the master.

Copy link
Contributor

Choose a reason for hiding this comment

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

On the master side, we'll need to check if the requested param equals <subsystem>.<tag>.certreq we'll need to get the value from the CSR file:
https://github.com/dogtagpki/pki/blob/master/base/server/src/main/java/com/netscape/cms/servlet/csadmin/GetConfigEntries.java#L156

Copy link
Member Author

Choose a reason for hiding this comment

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

I cannot verify what is present in the folder. It is not sure if it will be created but maybe I can check if they are provided. I'll do some tests.

.github/workflows/ca-clone-hsm-test.yml Outdated Show resolved Hide resolved
@fmarco76 fmarco76 force-pushed the ConfigurationFreeCSR branch from 28f4894 to c001e0f Compare October 13, 2023 08:27
@fmarco76 fmarco76 marked this pull request as draft October 13, 2023 10:48
@fmarco76 fmarco76 force-pushed the ConfigurationFreeCSR branch 7 times, most recently from bb2698e to 15f9fda Compare October 13, 2023 19:05
@fmarco76 fmarco76 marked this pull request as ready for review October 13, 2023 19:06
Copy link
Contributor

@edewata edewata left a comment

Choose a reason for hiding this comment

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

Thanks for the updates!

Please see my comments. I think we should fix the folder & file ownership, but the rest is just minor suggestions. If you prefer to fix the folder/file ownership in a separate PR that's fine too since we still have time before the release, so feel free to update/merge.

@fmarco76 fmarco76 force-pushed the ConfigurationFreeCSR branch 3 times, most recently from 908b8df to 436f01b Compare October 16, 2023 10:50
Copy link
Contributor

@edewata edewata left a comment

Choose a reason for hiding this comment

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

Thanks for the update! I added a few more suggestions, feel free to update/merge.

base/server/python/pki/server/subsystem.py Outdated Show resolved Hide resolved
base/server/python/pki/server/subsystem.py Show resolved Hide resolved
base/server/python/pki/server/deployment/__init__.py Outdated Show resolved Hide resolved
base/server/upgrade/11.5.0/04-RemoveCertCSRfromConfig.py Outdated Show resolved Hide resolved
base/server/upgrade/11.5.0/04-RemoveCertCSRfromConfig.py Outdated Show resolved Hide resolved
CSR are created and stored in `<instance_config>/certs` folder as `<certs_id>.csr` files.

Fix dogtagpki#2111
Add a check of CSR between CA master and clone.
@fmarco76 fmarco76 force-pushed the ConfigurationFreeCSR branch from d4f81ec to ce97033 Compare October 16, 2023 16:17
@edewata
Copy link
Contributor

edewata commented Oct 16, 2023

Thanks for the update! Sorry, I just realized something else. It looks like the CSR files are sometimes called <nickname>.csr and sometimes <cert ID>.csr. In the CI test it is fine since we use the same values, but in real deployments they could be different. I think it should be <cert ID>.csr so they will be consistent regardless of the actual nicknames.

@fmarco76
Copy link
Member Author

Thanks for the update! Sorry, I just realized something else. It looks like the CSR files are sometimes called <nickname>.csr and sometimes <cert ID>.csr. In the CI test it is fine since we use the same values, but in real deployments they could be different. I think it should be <cert ID>.csr so they will be consistent regardless of the actual nicknames.

I think CSRs are always called with <nickname>.csr. Initially, there were some cases different but it has been fixed. In the CI I did for IPA I get the nickname from the configuration so I do not guess the file name.

I used the nickname because the same cert_id is used among different subsystems. As an example, the audit_signing is defined for KRA and CA. The nickname should be unique, unless they use different token.
If different subsystem must the same certificates if <cert_id> is the same than we can use it.
I think this is last point to take care and then we can merge.

@edewata
Copy link
Contributor

edewata commented Oct 16, 2023

Sorry, I was thinking about cert IDs returned by pki-server cert-find command (yeah, it's a bit confusing since there are several things called cert ID too). These cert IDs are unique for the whole instance (e.g. ca_audit_signing) except for sslserver and subsystem:
https://github.com/dogtagpki/pki/blob/master/base/server/python/pki/server/cli/cert.py#L175-L176

But let's merge this PR as is, then we can discuss further about this issue later. Thanks!

@fmarco76 fmarco76 force-pushed the ConfigurationFreeCSR branch 4 times, most recently from a4e394c to 3e6614a Compare October 17, 2023 13:26
@fmarco76 fmarco76 force-pushed the ConfigurationFreeCSR branch from 3e6614a to cc58713 Compare October 17, 2023 13:54
@fmarco76
Copy link
Member Author

@edewata I have modified the file name so now they are stored as <cert_id>.csr where cert_id has the value reported by the command pki-server cert-find command.

If all the test are OK I think we can merge. We have to define how the healcheck should work now.

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 2 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@edewata
Copy link
Contributor

edewata commented Oct 17, 2023

Awesome! Thanks @fmarco76!

@fmarco76
Copy link
Member Author

@edewata Thanks!

@fmarco76 fmarco76 merged commit 61c3c27 into dogtagpki:master Oct 17, 2023
143 of 144 checks passed
@fmarco76 fmarco76 deleted the ConfigurationFreeCSR branch October 17, 2023 16:25
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.

Redundant cert requests in CS.cfg
2 participants