feat: add --syncvalues flag and improve secret sharing #5
Reference in New Issue
Block a user
No description provided.
Delete Branch "eCommons/alakazam:secret-sync"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
WHOOYAA! this PR contains some features I was really missing! Thank you a lot. Especially the
get_secret_from_host()function I like! Hopefully it can be replaced someday by abra directly: toolshed/abra#694Maybe this function can be extended to read the secrets, even if there are no running containers: toolshed/organising#480 (comment) but this could be somewhat for another issue.
@ -552,2 +574,2 @@insert_secret(app1_domain, app1_secret, secret)logging.info(f"Shared secret {app2_secret} from {app2_domain} to {app1_domain} as {app1_secret}")# Target has secret but source doesn't, warn instead of copying back.# Copying target to source risks overwriting the correct source value.I'm not sure how you argue to remove the bidirectional secret sharing? The order which app is source or target should be quite irrelevant.
The condition
app2_secret_is_stored and not app1_secret_is_stored:ensures, that no secret will be overwritten. Because the secret of app1 doesn't exists.@ -558,0 +595,4 @@except RuntimeError as e:logging.warning(f"Could not read secret for comparison ({app1_domain}/{app2_domain}): {e}")continueif app2_value is None or app1_value != app2_value:Maybe it should be stated somewhere, that the secret of app2 will be overwritten, not only if it differs from the secret of app1, but also if the container is not running. The result will be the same, but for clarity.
@ -558,0 +603,4 @@update_secret(app2_domain, app2_secret, app1_value, app2_container)else:logging.warning(f"Secret mismatch: {app1_domain}/{app1_secret} differs from "Here you should adapt the warning if the container is not running, because if it is not, the warning
Secret mismatch: {app1_domain}/{app1_secret} differs from...would be incorrect. Instead a message likecouldn't compare secret values, because {app1} is not runningwould be good.@ -579,0 +652,4 @@if server:breakif not server:raise RuntimeError(f"Could not determine server for {domain}")Instead of this for loop, you could use
get_server_apps()@ -665,6 +775,23 @@ def insert_secret(domain: str, secret_name: str, secret: str) -> None:abra("app", "secret", "insert", domain, secret_name, "v1", secret)def update_secret(domain: str, secret_name: str, secret: str, containers: List) -> None:for a more intuitive function signature it would be good to pass a boolean
was_deployedinstead of the complete list of containers.@ -892,3 +1026,3 @@insert_secrets_from_conf(domain, app_config)run_secret_hooks(domain, app_config)exchange_secrets(app, instance_config, instance_apps)# Pass 2: exchange secrets between apps, then generate any remaining missing secrets.I really like the idea of splitting the secret insertion and secret exchange into two phases. I've never run into the case that I wanted to explicitly insert a secret first and the exchange it, therefore I never thought about this case.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.