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

Allow custom validity dates over new X509 certificates #53149

Merged
merged 22 commits into from Apr 29, 2020
Merged

Allow custom validity dates over new X509 certificates #53149

merged 22 commits into from Apr 29, 2020

Conversation

jeduardo
Copy link
Contributor

@jeduardo jeduardo commented May 21, 2019

What does this PR do?

This PR makes it possible to issue certificates with custom dates using the Salt X509 support by specifying the not_before and not_after attributes to new certificates.

What issues does this PR fix or reference?

#53148

Previous Behavior

not_before and not_after attributes are ignored by the Salt x509 module and valid dates for a X509 certificate are always calculated from a dynamic calculation.

New Behavior

If not_before and not_after are specified, they are used as validity dates when issuing the new X509 certificate.

Tests written?

Yes

Commits signed with GPG?

No

salt/modules/x509.py Outdated Show resolved Hide resolved
salt/states/x509.py Outdated Show resolved Hide resolved
@twangboy
Copy link
Contributor

Also, can we get some tests for this please?

Copy link
Contributor

@Ch3LL Ch3LL left a comment

Choose a reason for hiding this comment

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

Can you add some tests for these new kwargs. Thanks :)

@jeduardo
Copy link
Contributor Author

@twangboy @Ch3LL sure, will look into adding documentation and tests. Thanks for the initial review!

@jeduardo
Copy link
Contributor Author

jeduardo commented Jun 1, 2019

@twangboy @Ch3LL I've added comments and tests where both were missing. Could you please give it another look?

tests/unit/modules/test_x509.py Outdated Show resolved Hide resolved
@Ch3LL
Copy link
Contributor

Ch3LL commented Jun 4, 2019

ping @clinta can you give this PR a review as well? thanks

@Ch3LL Ch3LL added the ZRELEASED - Neon retired label label Jun 6, 2019
@Ch3LL Ch3LL changed the base branch from develop to neon June 6, 2019 21:26
@Ch3LL
Copy link
Contributor

Ch3LL commented Jun 6, 2019

FYI I migrated this PR from develop to neon to ensure it is included in the upcoming neon release. Let me know if this caused any issues. Thanks

@jeduardo
Copy link
Contributor Author

jeduardo commented Jun 6, 2019

@Ch3LL Works On My Machine(tm) so I think it's all fine!

@Ch3LL
Copy link
Contributor

Ch3LL commented Jun 7, 2019

ping @twangboy just waiting on your re-review

and if we could also get a review from @clinta that would be ++

@jeduardo
Copy link
Contributor Author

@twangboy ping :)

@jeduardo jeduardo requested a review from a team as a code owner August 10, 2019 09:54
@ghost ghost requested a review from Akm0d August 10, 2019 09:55
salt/modules/x509.py Outdated Show resolved Hide resolved
salt/modules/x509.py Outdated Show resolved Hide resolved
salt/modules/x509.py Outdated Show resolved Hide resolved
Copy link
Contributor

@waynew waynew left a comment

Choose a reason for hiding this comment

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

Found a couple of more spots that need some attention.

tests/unit/modules/test_x509.py Outdated Show resolved Hide resolved
tests/unit/modules/test_x509.py Outdated Show resolved Hide resolved
tests/unit/modules/test_x509.py Outdated Show resolved Hide resolved
tests/unit/modules/test_x509.py Outdated Show resolved Hide resolved
tests/unit/modules/test_x509.py Outdated Show resolved Hide resolved
tests/unit/modules/test_x509.py Outdated Show resolved Hide resolved
@jeduardo
Copy link
Contributor Author

Hey @waynew, it took me a while to find time to look into this but I've applied all of your suggestions to the merge request. Could you please give it another look?

@jeduardo
Copy link
Contributor Author

jeduardo commented Nov 9, 2019

Ping... @waynew @Ch3LL

@Ch3LL
Copy link
Contributor

Ch3LL commented Dec 11, 2019

hey @jeduardo sorry for the late reply. We just recently changed our branch and releasing strategy as detailed in this SEP: saltstack/salt-enhancement-proposals#20

Any chance you would be willing to port this PR over to the master branch, since we will be releasing from this branch going forward. If not I can help you port this over there.

@jeduardo jeduardo changed the base branch from neon to master December 21, 2019 11:00
@jeduardo
Copy link
Contributor Author

Hey @Ch3LL. Not a problem, the fixes are not that many. I've ported them all to the master branch and changed the PR to point to master instead of Neon.

Whilst tests are Working On My Machine(tm), I've noticed that the CSR tests that were present in the Neon branch are no longer present in master. They have nothing to do with this fix but I thought it would be useful to mention it.

I would also ask for you to check if the versionadded comment for the new properties still applies and, if so, if it's correct or not.

Finally, Github seems to be complaining about many conflicts that must be resolved that seem to be caused by all the branch-changing and porting.

Could you please give it a pass and tell me if any changes are needed?

@jeduardo
Copy link
Contributor Author

Hey @Ch3LL, no idea what the black tool is and which pre-commit hooks you are using now, I've been unfortunately a bit away from playing more with the Salt build process since I switched jobs. Happy to learn more about these though if you have information to share. :)

In the meanwhile I've managed to perform the merge to master locally on my machine and all local test/lint runs completed fine, so I think this is resolved. Let's see what the automated tests will say after they're done.

@Ch3LL
Copy link
Contributor

Ch3LL commented Apr 17, 2020

thanks for doing that. it looks like the pre-commit is still failing.

There are some docs here: https://docs.saltstack.com/en/latest/topics/development/contributing.html#quickstart on how to get it setup. But essentially you just need to install/setup pre-commiit as per those docs. And then when you do a git commit it should automatically run the pre-commit hooks. Looks like in your instance isort and black are failing. The black tool is a python code formatter and isort sorts imports in the same way across all files. If you take a look at the jenkins output here: https://jenkinsci.saltstack.com/job/pr-pre-commit/job/PR-53149/4/console it actually provides you the diff if you want to just take that approach as well.

@jeduardo
Copy link
Contributor Author

@Ch3LL thanks for the helpful information! I was able to get pre-commit running here at my workstation and got some promising results:

isort....................................................................Passed
black....................................................................Passed
Lint Salt................................................................Passed
Lint Tests...............................................................Passed

Luckily this time everything will work fine. Fingers crossed here.

@Ch3LL
Copy link
Contributor

Ch3LL commented Apr 20, 2020

thanks for doing that. Looks like there is a merge conflict. I dont believe those doc test failures are related. When i rebased your PR on the head of master they started passing.

@jeduardo
Copy link
Contributor Author

Hey @Ch3LL, I was able, again, to merge the code on my machine but found that unfortunately some of the logic I needed to add to salt/states/x509.py causes a syntax error, as it depends on variable called current_days_remaining that no longer exists in the current version of the code in the certificate_managed function. It looks to me that some of it was recently rewritten.

I will need to have a deeper look at the current version of the code and most likely run it in a test instance to see if the changes are still required. I am not confident that just the merge will result in a working state and won't create a bigger bug.

@Ch3LL
Copy link
Contributor

Ch3LL commented Apr 23, 2020

let me know if i can help at all. thanks for diving in

@jeduardo
Copy link
Contributor Author

Hey @Ch3LL, I've added some integration tests covering the situations when someone specifies not_before, not_after, or both of them, exercising the state in addition to the unit tests covering the module.

I've executed these tests before and after the merge and got the same results in both of them, so I think the logic I had in the state can be safely discarded. Waiting for the automatic checks to run now and crossing fingers again.

@jeduardo
Copy link
Contributor Author

Autochecks look fine!

@dwoz
Copy link
Contributor

dwoz commented Apr 26, 2020

@waynew Are you good with this now?

Copy link
Contributor

@Ch3LL Ch3LL left a comment

Choose a reason for hiding this comment

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

just one more small change

@@ -150,6 +150,33 @@
- CN: www.example.com
- days_remaining: 30
- backup: True
- managed_private_key:
Copy link
Contributor

Choose a reason for hiding this comment

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

managed_private_key was removed on purpose here: https://github.com/saltstack/salt/pull/52935/files#diff-5499a295a50d60a761c34f4080e4014bL80 in favor of using the separate x509.private_key_managed state. Can you remove the reference here and on line 175.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey @Ch3LL, good catch. I remember seeing the change in the code but forgot to look for it in the docs. Just removed it, thanks!

Core Open PRs automation moved this from Assigned to In progress Apr 28, 2020
@Ch3LL
Copy link
Contributor

Ch3LL commented Apr 29, 2020

ping @waynew just need your review and we can get this one in :)

Copy link
Contributor

@waynew waynew left a comment

Choose a reason for hiding this comment

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

Excellent! Thanks for addressing those changes!

@dwoz dwoz merged commit ff4fd1e into saltstack:master Apr 29, 2020
Core Open PRs automation moved this from In progress to Done Apr 29, 2020
@jeduardo
Copy link
Contributor Author

Thanks all for merging it :)

@sagetherage sagetherage added this to In progress in Sodium via automation May 18, 2020
@sagetherage sagetherage moved this from In progress to Done in Sodium May 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Sodium
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

7 participants