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

Add support for overriding templated cert destinations #1098

Merged
merged 2 commits into from
Jun 21, 2024
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
27 changes: 27 additions & 0 deletions pkg/cli/trcconfigbase/trcconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ func CommonMain(envPtr *string,
secretMode := flagset.Bool("secretMode", true, "Only override secret values in templates?")
servicesWanted := flagset.String("servicesWanted", "", "Services to pull template values for, in the form 'service1,service2' (defaults to all services)")
wantCertsPtr := flagset.Bool("certs", false, "Pull certificates into directory specified by endDirPtr")
certDestPathPtr := flagset.String("certDestPath", "", "Override templated cert destination paths")
keyStorePtr := flagset.String("keystore", "", "Put certificates into this keystore file.")
logFilePtr := flagset.String("log", "./"+coreopts.BuildOptions.GetFolderPrefix(nil)+"config.log", "Output path for log file")
pingPtr := flagset.Bool("ping", false, "Ping vault.")
Expand All @@ -127,6 +128,7 @@ func CommonMain(envPtr *string,
versionInfoPtr := flagset.Bool("versions", false, "Version information about values")
insecurePtr := flagset.Bool("insecure", false, "By default, every ssl connection this tool makes is verified secure. This option allows to tool to continue with server connections considered insecure.")
noVaultPtr := flagset.Bool("novault", false, "Don't pull configuration data from vault.")

isShell := false

if driverConfig != nil {
Expand Down Expand Up @@ -219,6 +221,12 @@ func CommonMain(envPtr *string,
} else if *versionInfoPtr && *diffPtr {
fmt.Println("Cannot use -diff flag and -versionInfo flag together")
return errors.New("cannot use -diff flag and -versionInfo flag together")
} else if *wantCertsPtr && *diffPtr {
fmt.Println("Cannot use -diff flag and -certs flag together")
return errors.New("cannot use -diff flag and -certs flag together")
} else if *certDestPathPtr != "" && !*wantCertsPtr {
fmt.Println("Cannot use -certDestPath flag without including -certs flag")
return errors.New("Cannot use -certDestPath flag without including -certs flag")
} else if *versionInfoPtr && *templateInfoPtr {
fmt.Println("Cannot use -templateInfo flag and -versionInfo flag together")
return errors.New("cannot use -templateInfo flag and -versionInfo flag together")
Expand Down Expand Up @@ -354,6 +362,23 @@ func CommonMain(envPtr *string,
fileFilterSlice[0] = *fileFilterPtr
}

certOverrides := make(map[string]string, strings.Count(*certDestPathPtr, ",")+1)
if *certDestPathPtr != "" {
for _, rebind := range strings.Split(*certDestPathPtr, ",") {
split := strings.Split(rebind, ":")
if len(split) != 2 {
fmt.Println("Incorrect format for certDestPath: " + rebind)
return fmt.Errorf("Incorrect format for certDestPath: " + rebind)
}
certFileName, certFileDest := split[0], split[1]
if split[0] == "" || split[1] == "" {
fmt.Println("Incorrect format for certDestPath: " + rebind)
return fmt.Errorf("Incorrect format for certDestPath: " + rebind)
}
certOverrides[certFileName] = certFileDest
}
}

//channel receiver
go receiver(configCtx)
if *diffPtr {
Expand Down Expand Up @@ -411,6 +436,7 @@ func CommonMain(envPtr *string,
GenAuth: false,
OutputMemCache: driverConfigBase.OutputMemCache,
MemFs: driverConfigBase.MemFs,
CertPathOverrides: certOverrides,
Diff: *diffPtr,
Update: messenger,
FileFilter: fileFilterSlice,
Expand Down Expand Up @@ -466,6 +492,7 @@ func CommonMain(envPtr *string,
GenAuth: false,
OutputMemCache: driverConfigBase.OutputMemCache,
MemFs: driverConfigBase.MemFs,
CertPathOverrides: certOverrides,
Diff: *diffPtr,
FileFilter: fileFilterSlice,
VersionInfo: eUtils.VersionHelper,
Expand Down
4 changes: 4 additions & 0 deletions pkg/cli/trcconfigbase/utils/templateHelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,10 @@ func PopulateTemplate(driverConfig *eUtils.DriverConfig,
certPasswordVaultPath, hasCertPasswordVaultPath := valueData["certPasswordVaultPath"]
certBundleJks, hasCertBundleJks := valueData["certBundleJks"]

if driverConfig.CertPathOverrides[filename] != "" {
certDestPath = driverConfig.CertPathOverrides[filename]
}

if hasCertDefinition && hasCertSourcePath {
if !ok {
vaultCertErr := errors.New("No certDestPath in config template section of seed for this service. Unable to generate: " + certDestPath.(string))
Expand Down
9 changes: 5 additions & 4 deletions pkg/utils/driverconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,11 @@ type DriverConfig struct {

SecretMode bool
// Tierceron source and destination I/O
StartDir []string // Starting directory. possibly multiple
EndDir string
OutputMemCache bool
MemFs MemoryFileSystem
StartDir []string // Starting directory. possibly multiple
EndDir string
OutputMemCache bool
MemFs MemoryFileSystem
CertPathOverrides map[string]string // certFileName -> certDest

// Config modes....
ZeroConfig bool
Expand Down