Skip to content

Commit

Permalink
add deployment mode (#10)
Browse files Browse the repository at this point in the history
adds deployment (init container, sidecar)
  • Loading branch information
karthikvt26 authored Jan 24, 2025
2 parents 8eafed0 + fe4ec04 commit 465260f
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ testsecret
testsecretJson
iam_db_secret
main
*.secret
k_config.yaml
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- [Architecture](#architecture)
- [Deployment](#deployment)
- [Deployment Modes](#deployment-modes)
- [Configuration](#configuration)
- Provider types:
- [proxy_awsm_oauth](#proxy_awsm_oauth)
Expand Down Expand Up @@ -117,6 +118,12 @@ The secrets from file provider type should also be mounted to the specified loca
`kubectl exec -it <hasura_pod_id> -c secrets-management-proxy -- sh`
Once you are into the shell, try doing `cat secret/dbsecret.txt`. This should fetch you the templatised secret from your secret manager.

### Deployment Modes

Hasura secret refresher can be deployed as a sidecar or an init container (*defaults to sidecar* if not specified). The purposes of each are as follows
1. Init Container (initcontainer) - for initialization purposes like fetching secrets from external sources and exit
2. Sidecar (sidecar) - for assisting the main container for its lifetime

## Configuration
The Secrets Proxy requires a configuration file which contains configuration for secrets manager integration and other directives.

Expand Down
2 changes: 1 addition & 1 deletion config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ aws_iam_auth_rds:
region: "ap-south-1"
db_name: "postgres"
db_user: "karthikvt26_iam"
db_host: "rds-hasura12a42cb.cdaicbsap2wa.ap-south-1.rds.amazonaws.com"
db_host: "rds-hasura510778c.cdaicbsap2wa.ap-south-1.rds.amazonaws.com"
db_port: 5432
path: /home/karthikv/Work/hasura-dev/pgproxy/token_file

Expand Down
41 changes: 39 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ const (
ConfigFileCliFlagDescription = "path to config file"
)

type DeploymentType string

const (
InitContainer DeploymentType = "initcontainer"
Sidecar DeploymentType = "sidecar"
)

const (
aws_secrets_manager = "proxy_aws_secrets_manager"
aws_sm_oauth = "proxy_awssm_oauth"
Expand Down Expand Up @@ -47,7 +54,7 @@ func main() {

conf := viper.GetViper().AllSettings()

config, fileProviders, err := parseConfig(conf, logger)
config, fileProviders, deploymentType, err := parseConfig(conf, logger)
if err != nil {
initLogger.Fatal().Err(err).Msg("Unable to parse config file")
}
Expand All @@ -57,6 +64,26 @@ func main() {
logger.Info().Msgf("%d providers initialized: %d file provider, %d http provider",
totalProviders, len(fileProviders), len(config.Providers),
)

// if the type is init container, then we need to identify the last execution status to mark
// whether we are done with fileProvider or not?
// init-container cannot be used to detect loading of proxy based secret
// retriever
if deploymentType == InitContainer {
// Just run the refresh method and if anything fails, exit
for _, p := range fileProviders {
err := p.Refresh()
if err != nil {
// os.Exit() or something
logger.Err(err).Msg("Encountered an error while loading secrets from configured file providers")
os.Exit(1)
}
}
logger.Info().Msg("Loaded all secrets into file")
os.Exit(0)
// Exit gracefully
}

for _, p := range fileProviders {
go p.Start()
}
Expand Down Expand Up @@ -94,10 +121,20 @@ func getLogLevel(level string, logger zerolog.Logger) zerolog.Level {
}
}

func parseConfig(rawConfig map[string]interface{}, logger zerolog.Logger) (config server.Config, fileProviders []provider.FileProvider, err error) {
func parseConfig(rawConfig map[string]interface{}, logger zerolog.Logger) (config server.Config, fileProviders []provider.FileProvider, deploymentType DeploymentType, err error) {
config.Providers = make(map[string]provider.HttpProvider)
fileProviders = make([]provider.FileProvider, 0, 0)
for k, v := range rawConfig {
if k == "type" {
t := v.(string)
switch t {
case "initcontainer":
deploymentType = InitContainer
default:
deploymentType = Sidecar
}
continue
}
if k == "log_config" || k == "refresh_config" {
continue
}
Expand Down

0 comments on commit 465260f

Please sign in to comment.