-
Notifications
You must be signed in to change notification settings - Fork 147
Potential Policy workflow for Synchronizer leader election #2543
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| @startuml | ||
| start | ||
| repeat | ||
| if (am leader?) then (yes) | ||
| :update `leader-expiration` to future time (1); | ||
| else (no) | ||
| if (`leader-expiration` time has passed (2)?) then (yes) | ||
| :delete leader host (3); | ||
| :create leader host (4); | ||
| if (host create includes API key?) then (yes) | ||
| :update `leader-expiration` to future time (5); | ||
| else (no) | ||
| endif | ||
| else (no) | ||
| endif | ||
| endif | ||
| repeat while (sleep) | ||
| @enduml |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| # Synchronizer Auto-Failover | ||
|
|
||
| The following is an overview of the workflow for a Vault Sychronizer to gain leadership: | ||
|
|
||
|  | ||
|
|
||
| Given the following Policy: | ||
| ```yml | ||
| - !policy | ||
| id: conjur | ||
| body: | ||
| - !policy | ||
| id: vault-synchronizer | ||
| body: | ||
| - !variable leader-expiration | ||
|
|
||
| # The Group all Synchronizer hosts need to be added to. | ||
| - !group members | ||
|
|
||
| - !permit | ||
| role: !group members | ||
| privileges: [ read, execute, update ] | ||
| resources: | ||
| - !variable leader-expiration | ||
|
|
||
| - !policy | ||
| id: leader | ||
| owner: !group members | ||
|
|
||
| - !policy | ||
| id: vault-lines-of-business | ||
| owner: !group members | ||
| body: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess this "vault-lines-of-business" policy should be created without body, and Synchronizer should create variables for each LOBs during synchonization intervals.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great catch. I updated this in the Conjur Intro example above. |
||
| - !variable | ||
| id: lob-1 | ||
| mime_type: application/json | ||
| - !variable | ||
| id: lob-2 | ||
| mime_type: application/json | ||
| ``` | ||
|
|
||
| The following are the steps (using the API) listed above: | ||
|
|
||
| 1. Update `leader-expiration` to future time: | ||
|
|
||
| ```sh | ||
| POST /secrets/{account}/variable/conjur%2Fvault-synchronizer%2Fleader-expiration | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "secrets"? how about creating/updating variables for LOBs - will that also be under "secrets"?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this case |
||
|
|
||
| Time.now() + <time in seconds> // Save as Unix epoch time | ||
| ``` | ||
|
|
||
| 1. `leader-expiration` time has passed: | ||
|
|
||
| ```sh | ||
| GET /secrets/{account}/variable/conjur%2Fvault-synchronizer%2Fleader-expiration | ||
| ``` | ||
|
|
||
| Then compare returned Unix epoch time time to current Unix epoch time. | ||
|
|
||
| 1. Delete leader host: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens in the very first flow:
Should I check if that variable is set altogether with expiration date or can I just try to delete it and then try to create it.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Delete on a resource that's not present results in a no-op, so it should be fine to always attempt the delete before trying to claim "leader" status. |
||
|
|
||
| ```sh | ||
| PUT /policies/{account}/policy/conjur%2Fvault-synchronizer%2Fleader | ||
|
|
||
| # Policy to delete the current leader | ||
| - !delete | ||
| record: !host current-leader | ||
| ``` | ||
|
|
||
| 1. Create leader host: | ||
|
|
||
| ```sh | ||
| POST /policies/{account}/policy/conjur%2Fvault-synchronizer%2Fleader | ||
|
|
||
| # Policy to delete the current leader | ||
| - !host | ||
| id: current-leader | ||
| annotations: | ||
| host: "<this synchronizer's host name>" | ||
| ``` | ||
|
|
||
| If the above command returns a JSON object with an API, this Synchronizer is the new leader. If not, another Synchronizer won. | ||
|
|
||
| The annotation provides an indicator of the "current leader". | ||
|
|
||
| 1. Update `leader-expiration` to future time: | ||
|
|
||
| ```sh | ||
| POST /secrets/{account}/variable/conjur%2Fvault-synchronizer%2Fleader-expiration | ||
|
|
||
| Time.now() + <time in seconds> // Save as Unix epoch time | ||
| ``` | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How can I do that?
I see a few use cases here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@GrzegorzK-CA, I put together a working example in the Conjur Intro project: https://github.com/conjurdemos/conjur-intro/blob/vault-synchronizer/bin/dap#L428.
The only thing missing here is setting the JSON document with safe names and last updated dates. Bash does not like the double quotes of JSON. Because the JSON is passed through so many functions, I was not able to get it escaped correctly. I updated the variable via the UI to make sure it worked as expected. You should have no problem doing this with the .NET SDK.