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

feat: added credential_process option to config #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

elyzov
Copy link

@elyzov elyzov commented Feb 14, 2023

resolves #16

@kir4h
Copy link
Owner

kir4h commented Feb 17, 2023

Thanks @elyzov! I´ll try to take a look over the week-end

@codecov
Copy link

codecov bot commented Feb 18, 2023

Codecov Report

Patch coverage: 78.94% and project coverage change: -0.73 ⚠️

Comparison is base (f0d8850) 89.61% compared to head (9e5bfe8) 88.88%.

❗ Current head 9e5bfe8 differs from pull request most recent head 61575cc. Consider uploading reports for the commit 61575cc to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #17      +/-   ##
==========================================
- Coverage   89.61%   88.88%   -0.73%     
==========================================
  Files           6        7       +1     
  Lines         260      279      +19     
==========================================
+ Hits          233      248      +15     
- Misses         13       15       +2     
- Partials       14       16       +2     
Flag Coverage Δ
unittests 88.88% <78.94%> (-0.73%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
internal/pkg/credential/process.go 78.94% <78.94%> (ø)

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@kir4h kir4h self-requested a review February 18, 2023 16:02
Copy link
Owner

@kir4h kir4h left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution, love the way AWS CLI allows this, makes it pretty flexible.

To address:

  • Some minor comments
  • Couple of tests missing
  • Adding the new variable to the man config in README.md

Maybe something like

# External process for sourcing Vault token
# If specified, `token` will be ignored
# credential_process = "get-vault-token -f credential-process"

You already documented in its own section, but I like to have a complete configuration
someone can copy paste if needed.

  • Also one question: I see this new behaviour is added as configuration variable but not as a runtime argument; is this on purpose?

CHANGELOG.md Outdated

### Added

- Ability to specify `credential_process` option in the config to sourcing Vault token with an external process
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
- Ability to specify `credential_process` option in the config to sourcing Vault token with an external process
- Ability to specify `credential_process` option in the config to source Vault token from an external process

README.md Outdated
[global]
# Vault address
address = "http://127.0.0.1:8200"
# External process for sourcing Valet token
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
# External process for sourcing Valet token
# External process for sourcing Vault token

README.md Outdated
```json
{
"Version": "1",
"Token": "an Vault access token"
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
"Token": "an Vault access token"
"Token": "a Vault access token"

README.md Outdated
}
```

- **RVault** should run the process, parse the JSON from stdout, and add the token to the global configuration.
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
- **RVault** should run the process, parse the JSON from stdout, and add the token to the global configuration.
- **RVault** will run the process, parse the JSON from stdout, and add the token to the global configuration.

cmd/root.go Outdated
if err != nil {
klog.Exitf("Can't execute credential process '%s': %v", process, err)
}
viper.SetDefault("global.token", token)
Copy link
Owner

Choose a reason for hiding this comment

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

To get the behaviour stated in the documentation, viper.Set should be used instead. Otherwise an existing global.tokenin the configuration file will take precedence over the default value.

)

const (
DefaultVersion = "1"
Copy link
Owner

Choose a reason for hiding this comment

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

I would rather unexport this one as it's not consumed outside of the package

Copy link
Author

Choose a reason for hiding this comment

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

@kir4h I see your concerns, but, as far as I can see, it's not violates any security aspects, but allow to refer this values from the other packages if it's required. On the other hand your proposal restricts the usage of this variables within the single package and will require additional efforts to to provides them for extarnal usage if it's required. Maybe I can't see some other rational in your proposal, so could you please elaborate a bit with your point of view.

Copy link
Owner

Choose a reason for hiding this comment

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

Not security related, more in line of YAGNI principle (the reason I noticed was the code inspector showing a warning for it)

Also In my view exporting a constant makes think that the constant is used elsewhere, and thus a refactor could be a breaking change where in reality that variable was only consumed internally and thus there is no breaking change.

And if at some point we want to export it it´s just a matter of a small refactor to do so, no big effort there at all.

)

var (
NoCommandPassed = fmt.Errorf("expected at least a single command to execute")
Copy link
Owner

Choose a reason for hiding this comment

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

Same unexport comment

internal/pkg/credential/process.go Show resolved Hide resolved
Comment on lines +38 to +40
cmd.Env = []string{
fmt.Sprintf("VAULT_ADDR=%s", viper.GetString("global.address")),
}
Copy link
Owner

Choose a reason for hiding this comment

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

Worth documenting that this logic will inject VAULT_ADDR environment variable

internal/pkg/credential/process_test.go Show resolved Hide resolved
@elyzov elyzov requested a review from kir4h June 22, 2023 10:04
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.

Sourcing credentials with an external process
2 participants