-
Notifications
You must be signed in to change notification settings - Fork 2
feat: template secret builder from multiple secrets #30
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
Open
prochac
wants to merge
1
commit into
securestart:main
Choose a base branch
from
prochac:feat-secret-templates
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| API_KEY=sk_live_1234567890abcdef | ||
| APP_NAME=MyAwesomeApp | ||
|
|
||
| PG_USER=user | ||
| PG_PASS=password | ||
| PG_HOST=localhost | ||
| PG_DATABASE=mydb |
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,15 @@ | ||
| # Templates Usage Example | ||
| # This demonstrates using templates: It allows you to build a secret as a | ||
| # composite of multiple secrets from the source provider | ||
|
|
||
| inherit: false | ||
|
|
||
| providers: | ||
| - kind: dotenv | ||
| path: .env.templates | ||
| keys: | ||
| API_KEY: API_SECRET_KEY | ||
| APP_NAME: == | ||
| templates: # Use classic Go text/template syntax | ||
| PG_DSN: | | ||
| postgresql://{{ .Env.PG_USER }}:{{ .Env.PG_PASS }}@{{ .Env.PG_HOST }}:5432/{{ .Env.PG_DATABASE }} | ||
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 |
|---|---|---|
|
|
@@ -26,4 +26,3 @@ Example: | |
| func init() { | ||
| rootCmd.AddCommand(shCmd) | ||
| } | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -3,25 +3,27 @@ package config | |
| import ( | ||
| "fmt" | ||
| "os" | ||
| "text/template" | ||
|
|
||
| "gopkg.in/yaml.v3" | ||
| ) | ||
|
|
||
| // Config represents the main configuration structure | ||
| type Config struct { | ||
| Inherit bool `yaml:"inherit"` // Whether to inherit system environment variables (default: true) | ||
| Inherit bool `yaml:"inherit"` // Whether to inherit system environment variables (default: true) | ||
| Providers []ProviderConfig `yaml:"providers"` | ||
| } | ||
|
|
||
| // ProviderConfig represents a single provider configuration | ||
| // Each provider loads from a single source. To load multiple secrets from the same provider type, | ||
| // configure multiple provider instances with the same 'kind' but different 'id' values. | ||
| type ProviderConfig struct { | ||
| Kind string `yaml:"kind"` | ||
| ID string `yaml:"id,omitempty"` // Optional: defaults to 'kind'. Required if multiple providers share the same kind | ||
| Config map[string]interface{} `yaml:"-"` // Provider-specific configuration (e.g., path, region, endpoint, etc.) | ||
| Keys map[string]string `yaml:"keys,omitempty"` // Optional key mappings (source_key: target_key, or "==" to keep same name) | ||
| Env EnvVars `yaml:"env,omitempty"` | ||
| Kind string `yaml:"kind"` | ||
| ID string `yaml:"id,omitempty"` // Optional: defaults to 'kind'. Required if multiple providers share the same kind | ||
| Config map[string]interface{} `yaml:"-"` // Provider-specific configuration (e.g., path, region, endpoint, etc.) | ||
| Keys map[string]string `yaml:"keys,omitempty"` // Optional key mappings (source_key: target_key, or "==" to keep same name) | ||
| Templates []*template.Template `yaml:"templates,omitempty"` // Optional templates mappings (target_key: str(Go template)) | ||
|
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. note for me: fix the comment, it's not a map |
||
| Env EnvVars `yaml:"env,omitempty"` | ||
| } | ||
|
|
||
| // UnmarshalYAML implements custom YAML unmarshaling to capture provider-specific fields | ||
|
|
@@ -53,6 +55,21 @@ func (p *ProviderConfig) UnmarshalYAML(unmarshal func(interface{}) error) error | |
| delete(raw, "keys") | ||
| } | ||
|
|
||
| if templates, ok := raw["templates"].(map[string]interface{}); ok { | ||
| for k, v := range templates { | ||
| str, ok := v.(string) | ||
| if !ok { | ||
| return fmt.Errorf("invalid template format") | ||
| } | ||
| tmpl := template.New(k) | ||
| if _, err := tmpl.Parse(str); err != nil { | ||
| return err | ||
|
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. note for me: use |
||
| } | ||
| p.Templates = append(p.Templates, tmpl) | ||
| } | ||
| delete(raw, "templates") | ||
| } | ||
|
|
||
| if env, ok := raw["env"].(map[string]interface{}); ok { | ||
| p.Env = make(EnvVars) | ||
| for k, v := range env { | ||
|
|
||
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
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.
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.
I have a weird feeling about this. The
keysfield issrc -> dst, meanwhiletemplatesisdst <- src1+src2:/But
templatesreversing is impossible, and reversingkeysbreaks the backward compatibility.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.
why having separate attributes for the templates ? I guess it should be easier to directly apply it to the keys. It would be similar to expandConfigTemplates
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.
but then we need to fix the behavior of keys. Previously the idea is to have advanced mapping under the keys so that user can rename the key upon load. This also could be used to choose the keys to load.
When I saw my example, now it's ambiguous. Is it load everything plus PG_DSN, or it only contains PG_DSN. Based on the current behaviour, it will be only PG_DSN. 🤔