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: add support for non-Admin HMACs #273

Merged
merged 1 commit into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ contexts:
client_id: metal_client
client_secret: 456
hmac: YOUR_HMAC
hmacAuthType: THE_AUTH_TYPE_OF_YOUR_HMAC # Metal-Admin, Metal-Edit or Metal-View
```

Optional you can specify `issuer_type: generic` if you use other issuers as Dex, e.g. Keycloak (this will request scopes `openid,profile,email`):
Expand Down
7 changes: 6 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ func initConfigWithViperCtx(c *config) error {
if hmacKey == "" && ctx.HMAC != nil {
hmacKey = *ctx.HMAC
}
hmacAuthType := viper.GetString("hmac-auth-type")
if hmacAuthType == "" && ctx.HMACAuthType != "" {
hmacAuthType = ctx.HMACAuthType
}

apiToken := viper.GetString("api-token")

// if there is no api token explicitly specified we try to pull it out of the kubeconfig context
Expand All @@ -215,7 +220,7 @@ func initConfigWithViperCtx(c *config) error {
}
}

client, err := metalgo.NewDriver(driverURL, apiToken, hmacKey)
client, err := metalgo.NewDriver(driverURL, apiToken, hmacKey, metalgo.AuthType(hmacAuthType))
if err != nil {
return err
}
Expand Down
6 changes: 4 additions & 2 deletions pkg/api/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ type Context struct {
ClientID string `yaml:"client_id"`
ClientSecret string `yaml:"client_secret"`
HMAC *string `yaml:"hmac"`
HMACAuthType string `yaml:"hmac_auth_type,omitempty"`
}

var defaultCtx = Context{
ApiURL: "http://localhost:8080/cloud",
IssuerURL: "http://localhost:8080/",
ApiURL: "http://localhost:8080/cloud",
IssuerURL: "http://localhost:8080/",
HMACAuthType: "Metal-Admin",
}

func GetContexts() (*Contexts, error) {
Expand Down