-
Notifications
You must be signed in to change notification settings - Fork 2
feat(installer): support templated install configs from vault #457
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
19ea435
feat(installer): support templated install configs from vault
schrodit 8e4055f
chore(docs): Auto-update docs and licenses
schrodit 43bd82d
refactor(installer): address review feedback on config templating
schrodit 74cb162
review
schrodit 2fd0f39
chore(docs): Auto-update docs and licenses
schrodit ed85503
Merge branch 'main' into config-template
schrodit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| // Copyright (c) Codesphere Inc. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package cmd | ||
|
|
||
| import ( | ||
| "github.com/codesphere-cloud/cs-go/pkg/io" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| type TemplateCmd struct { | ||
| cmd *cobra.Command | ||
| } | ||
|
|
||
| func AddTemplateCmd(rootCmd *cobra.Command, opts *GlobalOptions) { | ||
| template := TemplateCmd{ | ||
| cmd: &cobra.Command{ | ||
| Use: "template", | ||
| Short: "Render OMS configuration templates", | ||
| Long: io.Long(`Render OMS configuration templates.`), | ||
| }, | ||
| } | ||
|
|
||
| AddTemplateConfigCmd(template.cmd, opts) | ||
| AddCmd(rootCmd, template.cmd) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| // Copyright (c) Codesphere Inc. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package cmd | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os" | ||
|
|
||
| "github.com/codesphere-cloud/cs-go/pkg/io" | ||
| "github.com/codesphere-cloud/oms/internal/configtemplating" | ||
| "github.com/codesphere-cloud/oms/internal/installer" | ||
| "github.com/codesphere-cloud/oms/internal/util" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| type TemplateConfigCmd struct { | ||
| cmd *cobra.Command | ||
| Opts TemplateConfigOpts | ||
| } | ||
|
|
||
| type TemplateConfigOpts struct { | ||
| *GlobalOptions | ||
| Config string | ||
| Vault string | ||
| AgeKey string | ||
| } | ||
|
|
||
| func (c *TemplateConfigCmd) RunE(cmd *cobra.Command, _ []string) error { | ||
| rendered, err := c.Render() | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if _, err := fmt.Fprintln(cmd.ErrOrStderr(), "Warning: the rendered config is printed to stdout in plaintext and may contain secrets from the vault."); err != nil { | ||
| return fmt.Errorf("failed to write warning message: %w", err) | ||
| } | ||
|
|
||
| if _, err := fmt.Fprint(cmd.OutOrStdout(), string(rendered)); err != nil { | ||
| return fmt.Errorf("failed to write rendered config: %w", err) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func AddTemplateConfigCmd(parentCmd *cobra.Command, opts *GlobalOptions) { | ||
| configCmd := &TemplateConfigCmd{ | ||
| cmd: &cobra.Command{ | ||
| Use: "config", | ||
| Short: "Render a config.yaml template using secrets from a vault file", | ||
|
schrodit marked this conversation as resolved.
|
||
| Long: io.Long(`Render a config.yaml template using secrets from a prod.vault.yaml file. | ||
|
|
||
| This command prints the rendered configuration to stdout so templating can be tested without running an installation. | ||
|
|
||
| Template syntax in config.yaml: | ||
|
|
||
| # Inject a secret value (defaults to the "content"/"password" field) | ||
| someKey: "{{ secret "mySecret" }}" | ||
|
|
||
| # Select a specific field | ||
| username: "{{ secret "mySecret" "fields.username" }}" | ||
| password: "{{ secret "mySecret" "fields.password" }}" | ||
|
|
||
| # Inject a file secret's content | ||
| caCert: "{{ secret "caCert" "file.content" }}" | ||
|
|
||
| Secret names and selectors must match entries in the prod.vault.yaml file.`), | ||
| Example: formatExamples("template config", []io.Example{ | ||
|
schrodit marked this conversation as resolved.
|
||
| { | ||
| Cmd: "--config config.yaml --vault prod.vault.yaml --age-key age_key.txt", | ||
| Desc: "Render config.yaml with secrets from prod.vault.yaml", | ||
| }, | ||
| }), | ||
| Args: cobra.ExactArgs(0), | ||
| }, | ||
| Opts: TemplateConfigOpts{GlobalOptions: opts}, | ||
| } | ||
|
|
||
| configCmd.cmd.Flags().StringVarP(&configCmd.Opts.Config, "config", "c", "", "Path to the config.yaml template to render (required)") | ||
| configCmd.cmd.Flags().StringVarP(&configCmd.Opts.Vault, "vault", "v", "", "Path to the SOPS-encrypted prod.vault.yaml file (required)") | ||
| configCmd.cmd.Flags().StringVarP(&configCmd.Opts.AgeKey, "age-key", "k", "", "Path to the age key file used to decrypt the vault (required)") | ||
|
|
||
| util.MarkFlagRequired(configCmd.cmd, "config") | ||
| util.MarkFlagRequired(configCmd.cmd, "vault") | ||
| util.MarkFlagRequired(configCmd.cmd, "age-key") | ||
|
|
||
| AddCmd(parentCmd, configCmd.cmd) | ||
|
|
||
| configCmd.cmd.RunE = configCmd.RunE | ||
| } | ||
|
|
||
| func (c *TemplateConfigCmd) Render() ([]byte, error) { | ||
| data, err := os.ReadFile(c.Opts.Config) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to read config file %s: %w", c.Opts.Config, err) | ||
| } | ||
|
|
||
| store := installer.NewLazyVaultTemplatingSecretStore(c.Opts.Vault, c.Opts.AgeKey) | ||
| rendered, err := configtemplating.RenderInstallConfigTemplate(data, store) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to render config template: %w", err) | ||
| } | ||
|
|
||
| return rendered, nil | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.