Skip to content
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
8 changes: 5 additions & 3 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1579,8 +1579,10 @@ var expectedConf = &Config{
HTTPClientConfig: config.DefaultHTTPClientConfig,
ServiceDiscoveryConfigs: discovery.Configs{
&stackit.SDConfig{
Project: "11111111-1111-1111-1111-111111111111",
Region: "eu01",
Project: "11111111-1111-1111-1111-111111111111",
ServiceAccountKey: "mysecret_sa_key",
PrivateKey: "mysecret_private_key",
Region: "eu01",
HTTPClientConfig: config.HTTPClientConfig{
Authorization: &config.Authorization{
Type: "Bearer",
Expand Down Expand Up @@ -2157,7 +2159,7 @@ func TestElideSecrets(t *testing.T) {
yamlConfig := string(config)

matches := secretRe.FindAllStringIndex(yamlConfig, -1)
require.Len(t, matches, 26, "wrong number of secret matches found")
require.Len(t, matches, 28, "wrong number of secret matches found")
require.NotContains(t, yamlConfig, "mysecret",
"yaml marshal reveals authentication credentials.")
}
Expand Down
2 changes: 2 additions & 0 deletions config/testdata/conf.good.yml
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,8 @@ scrape_configs:
- job_name: stackit-servers
stackit_sd_configs:
- project: 11111111-1111-1111-1111-111111111111
service_account_key: mysecret_sa_key
private_key: mysecret_private_key
authorization:
credentials: abcdef

Expand Down
4 changes: 2 additions & 2 deletions discovery/stackit/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ func newServerDiscovery(conf *SDConfig, logger *slog.Logger) (*iaasDiscovery, er
Servers: servers,
NoAuth: conf.ServiceAccountKey == "" && conf.ServiceAccountKeyPath == "",

ServiceAccountKey: conf.ServiceAccountKey,
PrivateKey: conf.PrivateKey,
ServiceAccountKey: string(conf.ServiceAccountKey),
PrivateKey: string(conf.PrivateKey),
ServiceAccountKeyPath: conf.ServiceAccountKeyPath,
PrivateKeyPath: conf.PrivateKeyPath,
CredentialsFilePath: conf.CredentialsFilePath,
Expand Down
7 changes: 4 additions & 3 deletions discovery/stackit/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"encoding/pem"
"testing"

"github.com/prometheus/common/config"
"github.com/prometheus/common/model"
"github.com/prometheus/common/promslog"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -59,12 +60,12 @@ func TestServerSDRefresh(t *testing.T) {
require.NoError(t, err)

cfg := DefaultSDConfig
cfg.PrivateKey = string(pem.EncodeToMemory(&pem.Block{
cfg.PrivateKey = config.Secret(pem.EncodeToMemory(&pem.Block{
Type: "RSA PRIVATE KEY",
Bytes: x509.MarshalPKCS1PrivateKey(key),
}))

cfg.ServiceAccountKey = `{
cfg.ServiceAccountKey = config.Secret(`{
"Active": true,
"CreatedAt": "2025-04-05T12:34:56Z",
"Credentials": {
Expand All @@ -79,7 +80,7 @@ func TestServerSDRefresh(t *testing.T) {
"KeyType": "USER_MANAGED",
"PublicKey": "...",
"ValidUntil": "2025-04-05T13:34:56Z"
}`
}`)

return cfg
}(),
Expand Down
4 changes: 2 additions & 2 deletions discovery/stackit/stackit.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ type SDConfig struct {
Port int `yaml:"port,omitempty"`
Region string `yaml:"region,omitempty"`
Endpoint string `yaml:"endpoint,omitempty"`
ServiceAccountKey string `yaml:"service_account_key,omitempty"`
PrivateKey string `yaml:"private_key,omitempty"`
ServiceAccountKey config.Secret `yaml:"service_account_key,omitempty"`
PrivateKey config.Secret `yaml:"private_key,omitempty"`
ServiceAccountKeyPath string `yaml:"service_account_key_path,omitempty"`
PrivateKeyPath string `yaml:"private_key_path,omitempty"`
CredentialsFilePath string `yaml:"credentials_file_path,omitempty"`
Expand Down
Loading