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
17 changes: 9 additions & 8 deletions cmd/ci-operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,8 @@ type options struct {
enableSecretsStoreCSIDriver bool
gsmConfigPath string
gsmConfig api.GSMConfig
gsmProjectConfigPath string
gsmProjectConfig gsm.Config
gsmCredentialsFile string

metricsAgent *metrics.MetricsAgent
Expand Down Expand Up @@ -514,7 +516,8 @@ func bindOptions(flag *flag.FlagSet) *options {
flag.StringVar(&opt.impersonateUser, "as", "", "Username to impersonate")
flag.BoolVar(&opt.restrictNetworkAccess, "restrict-network-access", false, "Restrict network access to 10.0.0.0/8 (RedHat intranet).")
flag.BoolVar(&opt.enableSecretsStoreCSIDriver, "enable-secrets-store-csi-driver", false, "Use Secrets Store CSI driver for accessing multi-stage credentials.")
flag.StringVar(&opt.gsmConfigPath, "gsm-config", "", "Path to the gsm config file.")
flag.StringVar(&opt.gsmConfigPath, "gsm-config", "", "Path to the gsm secrets config file.")
flag.StringVar(&opt.gsmProjectConfigPath, "gsm-project-config", "", "Path to the GSM project config file.")
flag.StringVar(&opt.gsmCredentialsFile, "gsm-credentials-file", "", "Path to GCP service account credentials.")

// flags needed for the configresolver
Expand Down Expand Up @@ -769,8 +772,10 @@ func (o *options) Complete() error {
handleTargetAdditionalSuffix(o)

if o.enableSecretsStoreCSIDriver {
err := api.LoadGSMConfigFromFile(o.gsmConfigPath, &o.gsmConfig)
if err != nil {
if err := api.LoadGSMConfigFromFile(o.gsmConfigPath, &o.gsmConfig); err != nil {
return err
}
if err = api.LoadGSMProjectConfigFromFile(o.gsmProjectConfigPath, &o.gsmProjectConfig); err != nil {
return err
}
}
Expand Down Expand Up @@ -1062,10 +1067,6 @@ func (o *options) Run() (errs []error) {

var gsmConfig *multi_stage.GSMConfiguration
if o.enableSecretsStoreCSIDriver {
gsmProjectConfig, err := gsm.GetConfigFromEnv()
if err != nil {
return []error{results.ForReason("gsm_config").WithError(err).Errorf("failed to get GSM project config from environment: %v", err)}
}
var opts []option.ClientOption
if o.gsmCredentialsFile != "" {
opts = append(opts, option.WithCredentialsFile(o.gsmCredentialsFile))
Expand All @@ -1082,7 +1083,7 @@ func (o *options) Run() (errs []error) {
gsmConfig = &multi_stage.GSMConfiguration{
Config: &o.gsmConfig,
CredentialsFile: o.gsmCredentialsFile,
ProjectConfig: gsmProjectConfig,
ProjectConfig: o.gsmProjectConfig,
Client: gsmClient,
}
}
Expand Down
16 changes: 16 additions & 0 deletions pkg/api/gsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
utilerrors "k8s.io/apimachinery/pkg/util/errors"
"sigs.k8s.io/yaml"

gsm "github.com/openshift/ci-tools/pkg/gsm-secrets"
gsmvalidation "github.com/openshift/ci-tools/pkg/gsm-validation"
"github.com/openshift/ci-tools/pkg/util/gzip"
)
Expand Down Expand Up @@ -91,6 +92,21 @@ func LoadGSMConfigFromFile(file string, config *GSMConfig) error {
return yaml.UnmarshalStrict(bytes, config)
}

// LoadGSMProjectConfigFromFile loads a GSM project configuration from a YAML file
func LoadGSMProjectConfigFromFile(file string, config *gsm.Config) error {
bytes, err := gzip.ReadFileMaybeGZIP(file)
if err != nil {
return fmt.Errorf("couldn't read GSM project config file: %w", err)
}
if err := yaml.UnmarshalStrict(bytes, config); err != nil {
return err
}
if strings.TrimSpace(config.ProjectIdString) == "" || strings.TrimSpace(config.ProjectIdNumber) == "" {
return fmt.Errorf("GSM project config must define non-empty GCP_PROJECT_ID and GCP_PROJECT_NUMBER")
}
return nil
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

func (c *GSMConfig) UnmarshalJSON(d []byte) error {
type Alias GSMConfig
aux := (*Alias)(c)
Expand Down
9 changes: 2 additions & 7 deletions pkg/gsm-secrets/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,8 @@ const (
)

type Config struct {
ProjectIdString string
ProjectIdNumber string
}

var Production = Config{
ProjectIdString: "openshift-ci-secrets",
ProjectIdNumber: "384486694155",
ProjectIdString string `json:"GCP_PROJECT_ID" yaml:"GCP_PROJECT_ID"`
ProjectIdNumber string `json:"GCP_PROJECT_NUMBER" yaml:"GCP_PROJECT_NUMBER"`
}

func (c Config) GetSecretAccessorRole() string {
Expand Down