Commit Graph
691 Commits
Author SHA1 Message Date
Tim Bruijnzeels 69cf3a01c6 Add code comments to explain logic better. 2021-04-13 15:37:06 +02:00
Tim Bruijnzeels bb159db14a Use a write lock for the full duration of updating CaObjects with a closure. 2021-04-13 15:13:08 +02:00
8a36517126 Error handling fixes and improvements (#464)
Fixes:
* Just use the token we have if we would ideally refresh before expiration but don't have a refresh token.
* Don't hide useful OpenID Connect error details (such as self-signed cert rejected instead of just request failed). (fixes #427)
* Lagosta fixes from branch issue-379-handle-connection-issues commit 58f5ccc7 (relates to #442).

Functional improvements:
* Return or log less in some error scenarios (#419).
* Upgrade to Oso 0.11.2 to get a MUCH better error report when a ?= query in a .polar file fails, plus the Mutex around Oso is no longer needed.
* Log when OIDC discovery completes successfully.
* Be cautious, just log connection issues to the OpenID Connect provider for now, don't retry discovery.
* Use a lower timeout for the OpenID Connect HTTP client than the normal Krill HTTP client.
* Log more cause chains where available.

Code quality improvements:
* Apply review feddback: unwrap locks and crash out via panic to be consistent with the rest of Krill.
* Factor out the repeated RAII guard handling.
* Split login() out into helper methods.
* Removed TODO comment.

Testing improvements:
* Removed left-behind debug screenshot.
* Add a test to show a bug whereby access is wrongly denied if a token is pending expiration and has no refresh token. 
* Add a test to make sure Krill handles timeout of requests to the OIDC provider correctly. Also adds support for a lower timeout in test mode ala how it's done elsewhere in Krill, and more faithfully replicates the normal Krill HTTP client configuration when configuring the OIDC HTTP client. Also factored the OIDC HTTP client code out as it is getting too large to live in provider.rs.
* Extend the OpenID Connect provider not available test to show that Krill copes with the provider being unavailable and coming back to life again.
* Re-worked the test/mock relationship so that the mock no longer has hard-coded users and username based behaviour activation but rather now the test sets the desired behaviour and is thus easier to understand and more flexible.
* Extended the OpenID Connect mock so that its endpoints can be disabled and enabled during tests, and be disabled before Krill even does initial discovery.
* Use example.com based bad ACR ID token.
* Remove support for the NoResponse mock failure mode as it blocks the tiny http server thread indefinitely also preventing a test using it from exiting, and adds little no perceived benefit over the SlowResponse failure mode (which does at least stop blocking within the expected test run time).
* The mock OpenID Connect provider must be shutdown before the UI test result is asserted, otherwise the test process never terminates.
* Use the expected OpenID Connect provider timeout when in test mode.
* Extend the openid connect test to test the 'hybrid' user attributes case.
* Give the login more time to complete before expiring the access token. (#466).
* Wait for the right backend status BEFORE clicking the ROAs tab. (#465)

Other:
* OpenID Connect log message consistency tweaks.
* Sync with updated correspoinding Lagosta branch commit d2a92fe1 with latest Lagosta master merged in and a yarn build empty catch block fix.
* Sync with commit b9a2f5b3 in the corresponding PR branch in Lagosta to get a testbed REST API client fix.

Co-authored-by: Tim Bruijnzeels <tim@nlnetlabs.nl>
2021-04-13 12:13:18 +02:00
Tim Bruijnzeels ca106f6d7a Improve handling of 0 second durations for key roll init and activate actions. 2021-04-13 11:05:30 +02:00
7cb5674033 Stabilize API and CLI (#330 and #360)
* Move child_request API endpoint for conststency. (#330)
* Move get RFC 8183 Publisher Request API endpoints (#330)
* Accept XML and json to add/update parent on same endpoints (#330)
* Simplify the JSON to add a child and remove unused fields. (#330)
* Update path to child_request in openapi spec.
* Update path to publisher request.
* Update api spec and documentation.
* Fix update parent API documentation and call by CLI.
* CLI stability
* Update pubd OpenAPI spec t o match changes made to the Krill API.
* Update the e2e test client code to submit only the id_cert and not the whole RFC8183 request, as required by changes made to the Krill API.

Co-authored-by: Ximon Eighteen <3304436+ximon18@users.noreply.github.com>
2021-04-12 17:24:41 +02:00
Ximon EighteenandGitHub 5c15953738 Add developer docs for the multi-user feature. (#456) 2021-04-12 12:27:31 +02:00
a715c82f7f Remove embedded repo/ca choices (#461)
* Remove embedded repository contact option, migrate commands and events.
* Migrate old CA init events. Test upgrade from 0.6.0.
* Migrate embedded in CA history.

Co-authored-by: Ximon Eighteen <3304436+ximon18@users.noreply.github.com>
2021-04-01 17:18:28 +02:00
Tim BruijnzeelsandGitHub 3a916cb632 Limit the number of deltas in RRDP notification.xml file. (#460) 2021-04-01 15:53:11 +02:00
Tim BruijnzeelsandGitHub dc3512bb26 Retry removing files from old repositories X(==5) times before giving up (#458)
* Retry removing files from old repositories X(==5) times before giving up.
* Add more server side error logging for publication failures.
2021-03-26 13:09:26 +01:00
Ximon Eighteen f2fd4ba75d Upgrade to Oso 0.11.2 to get a MUCH better error report when a ?= query in a .polar file fails, plus the Mutex around Oso is no longer needed. 2021-03-26 09:10:02 +01:00
Ximon EighteenandGitHub f3e8023be5 Support fine grained access per CA (resolves #437) (#443)
- Various changes to support a grey policy in between black and white approach of permitting or denying access to CAs entirely, whereby a user can have a different role in one CA than in another.
- Introduces the NoResourceType for requests not relating to a specific "resource", e.g. CA, such as LOGIN. NoResourceType maps to `nil` in Oso policy language.
- Add support for Permission constants in Polar files. Build the Permission enum using a macro.
- Added CA_ADMIN (for bulk operations) and CA_DELETE permissions.
- Support loading more than one custom auth policy file.
- Checks were missing on some API calls if the user had the necessary permission *on the relevant resources*.
- Rename the team policy as a demo to indicate that it is educational only.
- Split a role-per-ca demo out of the team policy demo.
- Extend the with_ta Cypress test to cover the role-per-ca ca demo policy (as it creates the needed data).
- Don't misrepresent an external policy file in log statements as being internal.
- Better comments describing what the tests are doing.
- Remove unused role parameter in team access demo policy.
- Add disallow() in Oso policies as a way to define deny rules.
2021-03-25 21:35:38 +01:00
Tim BruijnzeelsandGitHub 3232adb57d Schedule parent/repo syncs even if there is another sync on the queue. (#445) 2021-03-23 10:14:03 +01:00
23be0b5ef7 Make testbed fully configurable through config section
* Let users configure the AIA to use with TA certificates. Set 'ta_aia' in the config file. (#409)
* Use explicit configuration section for testbed, no longer rely on magic env variables.

Note: this will all be revised again if/when the Publication server and TA vs CA code is fully separated in future.

Co-authored-by: Ximon Eighteen <3304436+ximon18@users.noreply.github.com>
2021-03-22 16:53:41 +01:00
Ximon EighteenandGitHub db08b466b2 FIX: Don't log DEBUG level messages when log_level is set to 'info' (fixes #434). (#435) 2021-03-17 13:42:45 +01:00
e662c1553b Change to a hybrid event sourcing model for CAs and Repository. (#426)
This allows us to keep the full history of semantically important events, while not spamming the history and avoiding excessive use of disk space. See issues #370 and #423.

This is a substantial change. Highlights follow:
* Added a developer documentation section
* No longer using events for manifest/crl generation (#370)
* No longer using events for publication deltas (#423)
* Removed pre 0.6.0 migration code - people will have to upgrade to at least 0.6.0 first
* Added migration code for 0.6.0-0.8.1 to this
* Migrate repository by doing a keyroll. (#370)
* Remove archiving code for commands (no longer applicable)

Minor other fixes:
* Use a swap file when writing (avoid corrupt json if disk is full) (#370)
* Make removing publisher content idempotent for publishers already removed.

Co-authored-by: Ximon Eighteen <3304436+ximon18@users.noreply.github.com>
Co-authored-by: Jasper den Hertog <jasper@plainspace.com>
2021-03-17 12:08:36 +01:00
Ximon EighteenandGitHub cf1f8a9c16 Improvements and fixes for e2e testing on the Krill dev branch (#439)
Note: Until merged to master this branch requires that a branch by the same name exists in the rpki-deploy repo with the corresponding changes to support these changes, which include:

- OpenAPI YML corrections.
- Support the new way to activate the TA.
- FIX: Include the correct ta.cer URI in the TAL.
- Use two seprarate Python libraries for Krill: one for CA REST SAPIs and one for PUB REST APIs.
- FIX: Test for the actual CAs and resources to create, as the presence of the testbed CA violates the previous check assumptions.
- FIX: Resource ASN, v4 and v6 values can no longer be assumed to have the same sort order as when given to Krill.
- Factor out test suite code into helper functions for better readability and maintainability.
- Retry RTR fetching (needed for ROAs obtained from Rcynic Lihttpd server served JSON as otherwise connecting too early results in SyncTimeout).

Known issues: on failure all RP tests will retry 3 times while actually only the Rcynic test should retry.
2021-03-15 12:10:08 +01:00
Ximon Eighteen 36cd630935 FIX: Incorrect variable used in log message. 2021-03-14 11:01:23 +01:00
Ximon Eighteen 16d578a053 Merge branch 'master' into v0.8.1-bis. 2021-03-09 10:58:06 +01:00
Ximon EighteenandGitHub 0f930f37ef Logout enhancements (closes #385, closes #397, fixes #408, closes #425) (#436)
- Formalize support for different logout strategies and add the fallback strategy.
- Generate the logout URL at logout time in preparation for supporting dynamic logout requests (as needed by token revocation).
- Secure the connection to the mock OpenID Connect provider with a self-signed TLS certificate.
- Allow self-signed certificates for HTTPS connections to localhost (same policy as elsewhere in Krill).
- Upgrade openidconnect-rs to latest v2.0.0 alpha to gain contributed support for OAuth 2.0 Token Revocation. (#385 and #397)
- Use reqwest 0.9.x directly instead of via the openidconnect-rs crate (we cannot use the v0.11.x reqwest that comes with the crate as (a) it doesn't permit self-signed certificates, (b) the blocking implementation was changed to be async which causes problems when inside an existing async runtime, and (c) switching the OpenID Connect client code over to be async is non-trivial - see #428).
- Pass the ID token as `id_token_hint` to the OpenID Connect RP-Initiated Logout 1.0 endpoint. (#408)
- Refined logic for the various logout mechanism permutations. (#425).
- Require OpenID Connection RP-Initiated Logout 1.0 and OAuth 2.0 Token Revocation endpoints to be HTTPS per the specs.
- Passes manual testing with Microsoft Azure Active Directory RP-Initiated Logout support and Google Compute Cloud OAuth 2.0 Token Revocation support.
- Added a Google Cloud Platform example to the comments in the default config file.
- Updated and added tests.
- Fixed logout and token revocation in the mock OpenID Connect provider to actually terminate login sessions.
- Handle a race condition in Lagosta where null user data was accessed that was just deleted due to logout.
- Handle errors from the Krill logout endpoint in Lagosta.
2021-03-08 23:39:45 +01:00
Ximon Eighteen ef1f47cbc2 Compilation fix resulting from PR merge. 2021-03-08 12:28:13 +01:00
Ximon EighteenandGitHub a12f065bf4 Auth related bug fixes and improvements (#432)
* FIX: don't permit users with empty roles to login.
* FIX: incorrect return value stated in JMESPath resub() fn docstring.
* FIX: Don't panic on unwrap() if the JMESPath resub() fn doesn't find a match.
* Show a useful error message if the JMESPath recap() or resub() fns are given an invalid regular expression as input, not an unwrap() with a source file and line number.
* Require a claim value to be non-empty after trimming whitespace in order to be considered a search match. Raise an error (and thus fail the OpenID Connect based login process) if an internal error occurs while doing JMESPath, as we can't trust the claim resolution outcome in that case.
2021-03-08 12:11:24 +01:00
Ximon EighteenandGitHub 47830dbf37 Check the OpenID Connect CSRF token (resolves #383). (#424)
Use a user agent cookie with strict security settings to verify the CSRF token. Adds a test to verify that passing the wrong CSRF state value to Krill correctly results in an error.
2021-03-08 12:09:13 +01:00
Ximon EighteenandGitHub a217f776af Log types passed to oso when trace is enabled (#430)
When trace level logging is enabled, log the types passed to Oso, not just the values.
2021-03-08 12:05:35 +01:00
Ximon EighteenandGitHub 2d0753ea19 Log errors that occur during Krill startup when started from a test. (#429) 2021-03-08 11:28:32 +01:00
Ximon EighteenandGitHub 824cf04f6b FIX: Correctly compare login session cache eviction timestamp to now. (fixes #390) (#399) 2021-02-10 14:26:33 +01:00
Ximon EighteenandGitHub 58c9cb5a4b Use strongly typed permissions in policy rules. (#417)
* Use strongly typed Permission checks instead of unrestricted String based checks.

* FIX: Don't include Permission:: in the message logged at WARN level about a user not having permission, only log the permission name, e.g. CA_CREATE.

* FIX: Also update the team policy demo polar file to use the new Permission type.
2021-02-10 12:29:53 +01:00
Ximon EighteenandGitHub 248807ebc7 Fix master token access restrictions when not using the multi-user feature. (#415)
* Add a test that should (but doesn't in non-multi-user mode) panic because it tries to create a CA using the wrong master token.

* cargo fmt

* Add some comments explaining what the test does and how it works.

* FIX: Don't permit anonymous users to perform restricted actions in non-multi-user mode (this regression was introduced in the v0.8.1-bis branch, it was never released).
2021-02-10 11:21:30 +01:00
Ximon EighteenandGitHub c226bc6d18 Use Rust named enum fields for more readable code. (#413) 2021-02-10 10:57:52 +01:00
Jasper den HertogandGitHub 1cba1dba70 authenticate()/try_refresh_token() rfc-6749 style errors (#396)
Improved handling of OpenID Connect error responses when using a refresh token to obtain new tokens.
2021-02-10 10:42:43 +01:00
Tim Bruijnzeels 19befdaada Check for pre-existing publication server more carefully. 2021-02-05 16:57:23 +01:00
Ximon EighteenandGitHub bbfe9a824a Testbed mode should be more liberal in handling formatting variations in child and publisher registration XML. (#369) (#403)
Testbed mode should be more liberal in handling formatting variations in child and publisher registration XML. Synced with Lagosta commit d94470db. (#369, #403)
2021-01-29 17:11:30 +01:00
Ximon Eighteen cb5a510238 Add a module level RustDoc comment to the OpenID Connect provider. 2021-01-25 10:51:31 +01:00
Ximon EighteenandGitHub c1ca53e13a Don't depend on private internal serde Display trait (fixes #391) 2021-01-19 16:05:05 +01:00
Jasper den Hertog ed6c080760 typo 2021-01-15 16:10:49 +01:00
Tim Bruijnzeels 1d1935e69d Move use statement into fn body with feature - stop confusing my IDE. 2021-01-13 09:59:45 +01:00
Ximon Eighteen 27a613ab01 FIX: 'Login denied for user' incorrectly reported due to use of string request path instead of RequestPath causing Oso policy rule match failure. 2021-01-12 17:12:44 +01:00
Ximon Eighteen 2b6ccd1b44 FIX: Don't bounce a logged user back to the login screen if they authenticate successfully but are denied LOGIN access by the authorisation policy. 2021-01-12 14:49:32 +01:00
Ximon Eighteen 8ef1660a1f Move ActorDef constructors to ActorDef. 2021-01-12 14:48:40 +01:00
Ximon Eighteen 6295cb6a73 FIX: Purge the session decryption cache on a frequency closer to the order of magnitude of session::MAX_CACHCE_SECS. 2021-01-12 13:19:13 +01:00
Ximon Eighteen dd8d2a2cab cargo fmt. 2021-01-12 00:13:01 +01:00
Ximon Eighteen adef1b7ad9 Clippy goodness. 2021-01-12 00:12:02 +01:00
Ximon Eighteen 1d315168bd Additional OpenID Connect provider comments relevant to the changes to support AWS Cognito. 2021-01-12 00:04:12 +01:00
Ximon Eighteen 6ffe5ceb53 FIX: Support OpenID Connect providers that don't advertise support for any of the logout mechanisms that we understand, but which do accept a HTTP redirect to a specified URL, such as AWS Cognito. 2021-01-12 00:02:14 +01:00
Ximon Eighteen 848fd72b8d FIX: Don't require response_modes_supported to be present in the OpenID Connect Discovery response as it is an optional field with the default value that we require. With this fix we can connect to the AWS Cognito OpenID Connect provider. 2021-01-11 23:59:01 +01:00
Ximon Eighteen 87cdf7962f FIX: Pass user attributes to Lagosta, not just the role. Synced with Lagosta master branch commit ac2dab37. 2021-01-09 14:55:06 +01:00
Tim Bruijnzeels 37750bab0d Be more lenient on whitespace in XML, but have better warnings for offending json. (#369) 2021-01-08 14:04:55 +01:00
Ximon Eighteen 1c3f915390 Merge branch 'v0.8.1-bis' of github.com:NLnetLabs/krill into v0.8.1-bis 2021-01-07 13:19:28 +01:00
Ximon Eighteen 60ab21b2be FIX: Ensure at the entrypoint that all API requests are authenticated which is more consistent with the v0.8.2 released code, is simpler (less code in each handler fn) and cannot be forgotten unlike checks in each handler fn. 2021-01-07 13:19:25 +01:00
Tim Bruijnzeels ece0950419 Remove HATEOS links from publisher list (make API consistent #330) 2021-01-07 09:56:26 +01:00
Ximon Eighteen 394e325b7c cargo fmt 2021-01-06 14:27:59 +01:00