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

janus_cli: automatically discover datastore keys #448

Merged
merged 3 commits into from
Sep 1, 2022

Conversation

tgeoghegan
Copy link
Contributor

In order to provision tasks, janus_cli needs the datastore key, used
encrypt some database rows. This key can be provided with
--datastore-keys, but since janus_cli has to talk to a Kubernetes
cluster anyway, it can also fetch the secret value from Kubernetes
secrets, which is fewer steps for an operator (no need to fetch the
secret before running janus_cli) and less risk of exposing the
datastore key to an operator workstation (or worse, an operator's
clipboard).

@tgeoghegan tgeoghegan requested a review from a team as a code owner August 30, 2022 21:37
long,
env = "SECRETS_K8S_NAMESPACE",
takes_value = true,
long_help = "Kubernetes namespace where datastore keyis stored. Required if \
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: typo

Suggested change
long_help = "Kubernetes namespace where datastore keyis stored. Required if \
long_help = "Kubernetes namespace where the datastore key is stored. Required if \

@tgeoghegan tgeoghegan force-pushed the timg/janus-cli-secrets branch from 51c3485 to 18433ef Compare August 31, 2022 02:35
Comment on lines 64 to 106
let k8s_client = kube::Client::try_default()
.await
.context("couldn't connect to Kubernetes environment")?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

With janus_cli decode-dap-message on the way, we should avoid constructing this client unless it is required by the subcommand, so that write-schema and decode-dap-message can be used on systems without kubeconfig files. once_cell::unsync::Lazy would be a convenient way to do so without duplication.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1, we should maintain that we don't access/connect to dependencies that are not used for the particular subcommand.

Comment on lines 64 to 106
let k8s_client = kube::Client::try_default()
.await
.context("couldn't connect to Kubernetes environment")?;
Copy link
Contributor

Choose a reason for hiding this comment

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

+1, we should maintain that we don't access/connect to dependencies that are not used for the particular subcommand.

@tgeoghegan
Copy link
Contributor Author

Downgrading to draft while I re-work the argument handling here and in #450

@tgeoghegan tgeoghegan marked this pull request as draft August 31, 2022 22:46
@tgeoghegan tgeoghegan force-pushed the timg/janus-cli-secrets branch 3 times, most recently from 2ca4a34 to 411c870 Compare September 1, 2022 00:06
@tgeoghegan tgeoghegan changed the base branch from main to timg/protocol-message-decoder September 1, 2022 00:06
@tgeoghegan tgeoghegan marked this pull request as ready for review September 1, 2022 00:06
@tgeoghegan
Copy link
Contributor Author

Comment on lines 104 to 107
let kube_client = kube::Client::try_default()
.await
.context("couldn't connect to Kubernetes environment")?;

Copy link
Collaborator

Choose a reason for hiding this comment

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

We need to defer this, and only run it inside the commands that require it. Otherwise, we may get the following error when it's not necessary.

Error: couldn't connect to Kubernetes environment

Caused by:
    0: Failed to infer configuration: failed to infer config: in-cluster: (failed to read the default namespace: No such file or directory (os error 2)), kubeconfig: (failed to read kubeconfig from '"/root/.kube/config"': No such file or directory (os error 2))
    1: failed to infer config: in-cluster: (failed to read the default namespace: No such file or directory (os error 2)), kubeconfig: (failed to read kubeconfig from '"/root/.kube/config"': No such file or directory (os error 2))
    2: failed to read kubeconfig from '"/root/.kube/config"': No such file or directory (os error 2)
    3: No such file or directory (os error 2)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whoops, I was sure I had caught this, but I think I got mixed up while rebasing.

In order to provision tasks, `janus_cli` needs the datastore key, used
encrypt some database rows. This key can be provided with
`--datastore-keys`, but since `janus_cli` has to talk to a Kubernetes
cluster anyway, it can also fetch the secret value from Kubernetes
secrets, which is fewer steps for an operator (no need to fetch the
secret before running `janus_cli`) and less risk of exposing the
datastore key to an operator workstation (or worse, an operator's
clipboard).

Resolves #409
Add a doctest for `janus_server::config::CommonConfig` with a minimal
example. This is principally useful so I can copy-paste this into a
config file for `janus_cli`.
When `janus_cli` provisions a task, it first deletes any task with the
provided `TaskId`, and ignores the error if it is "Not Found". But if
the `delete_task` method is annotated with
`#[tracing::instrument(err)]`, then you get a big, scary level=ERROR
line printed in RED to the console when `janus_cli` is run, even though
the error is benign. Remove the annotation to avoid operators
incorrectly thinking something has gone wrong.
@tgeoghegan tgeoghegan force-pushed the timg/janus-cli-secrets branch from 14d1f6a to e1348ed Compare September 1, 2022 19:50
@tgeoghegan tgeoghegan merged commit e3a288d into timg/protocol-message-decoder Sep 1, 2022
@tgeoghegan
Copy link
Contributor Author

Another day, another PR merged to the wrong target.

@tgeoghegan tgeoghegan deleted the timg/janus-cli-secrets branch October 12, 2022 19:21
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.

3 participants