Skip to content

Commit

Permalink
SSL initialism should be either lower or upper cased
Browse files Browse the repository at this point in the history
  • Loading branch information
cbosdo committed Nov 13, 2024
1 parent a6c3cb9 commit 33f0111
Show file tree
Hide file tree
Showing 23 changed files with 109 additions and 108 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ linters-settings:
- DB
# Added
- SCC
- SSL
gofmt:
simplify: true
gocyclo:
Expand Down
6 changes: 3 additions & 3 deletions mgradm/cmd/install/kubernetes/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ func installForKubernetes(globalFlags *types.GlobalFlags,
}

// Deploy the SSL CA or server certificate
ca := types.SslPair{}
sslArgs, err := kubernetes.DeployCertificate(&flags.Helm, &flags.Ssl, "", &ca, clusterInfos.GetKubeconfig(), fqdn,
ca := types.SSLPair{}
sslArgs, err := kubernetes.DeployCertificate(&flags.Helm, &flags.SSL, "", &ca, clusterInfos.GetKubeconfig(), fqdn,
flags.Image.PullPolicy)
if err != nil {
return shared_utils.Errorf(err, L("cannot deploy certificate"))
Expand All @@ -74,7 +74,7 @@ func installForKubernetes(globalFlags *types.GlobalFlags,
}

// Deploy Uyuni and wait for it to be up
if err := kubernetes.Deploy(cnx, flags.Image.Registry, &flags.Image, &flags.Helm, &flags.Ssl,
if err := kubernetes.Deploy(cnx, flags.Image.Registry, &flags.Image, &flags.Helm, &flags.SSL,
clusterInfos, fqdn, flags.Debug.Java, false, helmArgs...,
); err != nil {
return shared_utils.Errorf(err, L("cannot deploy uyuni"))
Expand Down
22 changes: 11 additions & 11 deletions mgradm/cmd/install/podman/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,20 @@ func installForPodman(
return utils.Errorf(err, L("cannot wait for system start"))
}

caPassword := flags.Ssl.Password
if flags.Ssl.UseExisting() {
caPassword := flags.SSL.Password
if flags.SSL.UseExisting() {
// We need to have a password for the generated CA, even though it will be thrown away after install
caPassword = "dummy"
}

env := map[string]string{
"CERT_O": flags.Ssl.Org,
"CERT_OU": flags.Ssl.OU,
"CERT_CITY": flags.Ssl.City,
"CERT_STATE": flags.Ssl.State,
"CERT_COUNTRY": flags.Ssl.Country,
"CERT_EMAIL": flags.Ssl.Email,
"CERT_CNAMES": strings.Join(append([]string{fqdn}, flags.Ssl.Cnames...), ","),
"CERT_O": flags.SSL.Org,
"CERT_OU": flags.SSL.OU,
"CERT_CITY": flags.SSL.City,
"CERT_STATE": flags.SSL.State,
"CERT_COUNTRY": flags.SSL.Country,
"CERT_EMAIL": flags.SSL.Email,
"CERT_CNAMES": strings.Join(append([]string{fqdn}, flags.SSL.Cnames...), ","),
"CERT_PASS": caPassword,
}

Expand Down Expand Up @@ -144,8 +144,8 @@ func installForPodman(
}
}

if flags.Ssl.UseExisting() {
if err := podman.UpdateSslCertificate(cnx, &flags.Ssl.Ca, &flags.Ssl.Server); err != nil {
if flags.SSL.UseExisting() {
if err := podman.UpdateSSLCertificate(cnx, &flags.SSL.Ca, &flags.SSL.Server); err != nil {
return utils.Errorf(err, L("cannot update SSL certificate"))
}
}
Expand Down
10 changes: 5 additions & 5 deletions mgradm/cmd/install/shared/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type InstallFlags struct {
Tftp bool
DB DBFlags
ReportDB DBFlags
Ssl cmd_utils.InstallSSLFlags
SSL cmd_utils.InstallSSLFlags
SCC types.SCCCredentials
Debug DebugFlags
Image types.ImageFlags `mapstructure:",squash"`
Expand Down Expand Up @@ -90,11 +90,11 @@ func (flags *InstallFlags) CheckParameters(cmd *cobra.Command, command string) {
}

// Make sure we have all the required 3rd party flags or none
flags.Ssl.CheckParameters()
flags.SSL.CheckParameters()

// Since we use cert-manager for self-signed certificates on kubernetes we don't need password for it
if !flags.Ssl.UseExisting() && command == "podman" {
utils.AskPasswordIfMissing(&flags.Ssl.Password, cmd.Flag("ssl-password").Usage, 0, 0)
if !flags.SSL.UseExisting() && command == "podman" {
utils.AskPasswordIfMissing(&flags.SSL.Password, cmd.Flag("ssl-password").Usage, 0, 0)
}

// Use the host timezone if the user didn't define one
Expand All @@ -109,7 +109,7 @@ func (flags *InstallFlags) CheckParameters(cmd *cobra.Command, command string) {
utils.AskPasswordIfMissing(&flags.Admin.Password, cmd.Flag("admin-password").Usage, 5, 48)
utils.AskIfMissing(&flags.Organization, cmd.Flag("organization").Usage, 3, 128, nil)

flags.Ssl.Email = flags.Email
flags.SSL.Email = flags.Email
flags.Admin.Email = flags.Email
}

Expand Down
2 changes: 1 addition & 1 deletion mgradm/cmd/migrate/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type kubernetesMigrateFlags struct {
shared.MigrateFlags `mapstructure:",squash"`
Helm cmd_utils.HelmFlags
SCC types.SCCCredentials
Ssl types.SslCertGenerationFlags
SSL types.SSLCertGenerationFlags
}

func newCmd(globalFlags *types.GlobalFlags, run utils.CommandFunc[kubernetesMigrateFlags]) *cobra.Command {
Expand Down
2 changes: 1 addition & 1 deletion mgradm/cmd/migrate/kubernetes/kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestParamsParsing(t *testing.T) {
flagstests.AssertHubXmlrpcFlag(t, cmd, &flags.HubXmlrpc)
testutils.AssertEquals(t, "Error parsing --user", "sudoer", flags.User)
flagstests.AssertServerHelmFlags(t, cmd, &flags.Helm)
testutils.AssertEquals(t, "Error parsing --ssl-password", "sslsecret", flags.Ssl.Password)
testutils.AssertEquals(t, "Error parsing --ssl-password", "sslsecret", flags.SSL.Password)
testutils.AssertEquals(t, "Wrong FQDN", "source.fq.dn", args[0])
return nil
}
Expand Down
10 changes: 5 additions & 5 deletions mgradm/cmd/migrate/kubernetes/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func migrateToKubernetes(
}
}()

setupSslArray, err := setupSsl(&flags.Helm, kubeconfig, scriptDir, flags.Ssl.Password, flags.Image.PullPolicy)
setupSSLArray, err := setupSSL(&flags.Helm, kubeconfig, scriptDir, flags.SSL.Password, flags.Image.PullPolicy)
if err != nil {
return utils.Errorf(err, L("cannot setup SSL"))
}
Expand All @@ -144,7 +144,7 @@ func migrateToKubernetes(
// TODO Handle claims for multi-node clusters
helmArgs = append(helmArgs, "--set", "mirror.hostPath="+flags.Mirror)
}
helmArgs = append(helmArgs, setupSslArray...)
helmArgs = append(helmArgs, setupSSLArray...)

// Run uyuni upgrade using the new ssl certificate
if err = kubernetes.UyuniUpgrade(
Expand Down Expand Up @@ -202,7 +202,7 @@ func migrateToKubernetes(

// updateIssuer replaces the temporary SSL certificate issuer with the source server CA.
// Return additional helm args to use the SSL certificates.
func setupSsl(
func setupSSL(
helm *adm_utils.HelmFlags,
kubeconfig string,
scriptDir string,
Expand All @@ -222,7 +222,7 @@ func setupSsl(
return []string{}, utils.Errorf(err, L("failed to strip text part from CA certificate"))
}
cert := base64.StdEncoding.EncodeToString(out)
ca := types.SslPair{Cert: cert, Key: key}
ca := types.SSLPair{Cert: cert, Key: key}

// An empty struct means no third party certificate
sslFlags := adm_utils.InstallSSLFlags{}
Expand All @@ -235,7 +235,7 @@ func setupSsl(
// Handle third party certificates and CA
sslFlags := adm_utils.InstallSSLFlags{
Ca: types.CaChain{Root: caCert},
Server: types.SslPair{
Server: types.SSLPair{
Key: path.Join(scriptDir, "spacewalk.key"),
Cert: path.Join(scriptDir, "spacewalk.crt"),
},
Expand Down
6 changes: 3 additions & 3 deletions mgradm/shared/kubernetes/certificates.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ func installTLSSecret(namespace string, serverCrt []byte, serverKey []byte, root
// Install cert-manager and its CRDs using helm in the cert-manager namespace if needed
// and then create a self-signed CA and issuers.
// Returns helm arguments to be added to use the issuer.
func installSslIssuers(helmFlags *cmd_utils.HelmFlags, sslFlags *cmd_utils.InstallSSLFlags, rootCa string,
tlsCert *types.SslPair, kubeconfig, fqdn string, imagePullPolicy string) ([]string, error) {
func installSSLIssuers(helmFlags *cmd_utils.HelmFlags, sslFlags *cmd_utils.InstallSSLFlags, rootCa string,
tlsCert *types.SSLPair, kubeconfig, fqdn string, imagePullPolicy string) ([]string, error) {
// Install cert-manager if needed
if err := installCertManager(helmFlags, kubeconfig, imagePullPolicy); err != nil {
return []string{}, utils.Errorf(err, L("cannot install cert manager"))
Expand Down Expand Up @@ -95,7 +95,7 @@ func installSslIssuers(helmFlags *cmd_utils.HelmFlags, sslFlags *cmd_utils.Insta
out, err := utils.RunCmdOutput(zerolog.DebugLevel, "kubectl", "get", "-o=jsonpath={.status.conditions[*].type}",
"issuer", "uyuni-ca-issuer", "-n", issuerData.Namespace)
if err == nil && string(out) == "Ready" {
return []string{"--set-json", "ingressSslAnnotations={\"cert-manager.io/issuer\": \"uyuni-ca-issuer\"}"}, nil
return []string{"--set-json", "ingressSSLAnnotations={\"cert-manager.io/issuer\": \"uyuni-ca-issuer\"}"}, nil
}
time.Sleep(1 * time.Second)
}
Expand Down
4 changes: 2 additions & 2 deletions mgradm/shared/kubernetes/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ func Deploy(

// DeployCertificate executre a deploy a new certificate given an helm.
func DeployCertificate(helmFlags *cmd_utils.HelmFlags, sslFlags *cmd_utils.InstallSSLFlags, rootCa string,
ca *types.SslPair, kubeconfig string, fqdn string, imagePullPolicy string) ([]string, error) {
ca *types.SSLPair, kubeconfig string, fqdn string, imagePullPolicy string) ([]string, error) {
helmArgs := []string{}
if sslFlags.UseExisting() {
if err := DeployExistingCertificate(helmFlags, sslFlags, kubeconfig); err != nil {
return helmArgs, err
}
} else {
// Install cert-manager and a self-signed issuer ready for use
issuerArgs, err := installSslIssuers(helmFlags, sslFlags, rootCa, ca, kubeconfig, fqdn, imagePullPolicy)
issuerArgs, err := installSSLIssuers(helmFlags, sslFlags, rootCa, ca, kubeconfig, fqdn, imagePullPolicy)
if err != nil {
return []string{}, utils.Errorf(err, L("cannot install cert-manager and self-sign issuer"))
}
Expand Down
4 changes: 2 additions & 2 deletions mgradm/shared/podman/podman.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ Environment="PODMAN_EXTRA_ARGS=%s"
return systemd.ReloadDaemon(false)
}

// UpdateSslCertificate update SSL certificate.
func UpdateSslCertificate(cnx *shared.Connection, chain *types.CaChain, serverPair *types.SslPair) error {
// UpdateSSLCertificate update SSL certificate.
func UpdateSSLCertificate(cnx *shared.Connection, chain *types.CaChain, serverPair *types.SSLPair) error {
ssl.CheckPaths(chain, serverPair)

// Copy the CAs, certificate and key to the container
Expand Down
4 changes: 2 additions & 2 deletions mgradm/shared/utils/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (

// InstallSSLFlags holds all the flags values related to SSL for installation.
type InstallSSLFlags struct {
types.SslCertGenerationFlags `mapstructure:",squash"`
types.SSLCertGenerationFlags `mapstructure:",squash"`
Ca types.CaChain
Server types.SslPair
Server types.SSLPair
}

// HelmFlags stores Uyuni and Cert Manager Helm information.
Expand Down
10 changes: 5 additions & 5 deletions mgrctl/cmd/proxy/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ type proxyFlags struct {
}

type caFlags struct {
types.SslPair `mapstructure:",squash"`
types.SSLPair `mapstructure:",squash"`
Password string
Intermediate []string
}

type proxyConfigSslFlags struct {
types.SslCertGenerationFlags `mapstructure:",squash"`
Proxy types.SslPair
type proxyConfigSSLFlags struct {
types.SSLCertGenerationFlags `mapstructure:",squash"`
Proxy types.SSLPair
Ca caFlags
}

Expand All @@ -55,7 +55,7 @@ type proxyCreateConfigFlags struct {
ConnectionDetails api.ConnectionDetails `mapstructure:"api"`
Proxy proxyFlags
Output string
Ssl proxyConfigSslFlags
SSL proxyConfigSSLFlags
}

// proxyCreateConfigRequiredFields is a set of required fields for validation.
Expand Down
32 changes: 16 additions & 16 deletions mgrctl/cmd/proxy/config_do.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ func proxyCreateConfig(
}

// handle CA certificate path
caCertificate := string(utils.ReadFile(flags.Ssl.Ca.Cert))
caCertificate := string(utils.ReadFile(flags.SSL.Ca.Cert))

// Check if ProxyCrt is provided to decide which configuration to run
var data *[]int8
if flags.Ssl.Proxy.Cert != "" {
if flags.SSL.Proxy.Cert != "" {
data, err = handleProxyConfig(client, flags, caCertificate, proxyConfig)
} else {
data, err = handleProxyConfigGenerate(client, flags, caCertificate, proxyConfigGenerate)
Expand All @@ -73,17 +73,17 @@ func handleProxyConfig(
proxyConfig func(client *api.APIClient, request proxy.ProxyConfigRequest) (*[]int8, error),
) (*[]int8, error) {
// Custom validations
if flags.Ssl.Proxy.Key == "" {
if flags.SSL.Proxy.Key == "" {
return nil, errors.New(L("flag proxyKey is required when flag proxyCrt is provided"))
}

// Read file paths for certificates and keys
proxyCrt := string(utils.ReadFile(flags.Ssl.Proxy.Cert))
proxyKey := string(utils.ReadFile(flags.Ssl.Proxy.Key))
proxyCrt := string(utils.ReadFile(flags.SSL.Proxy.Cert))
proxyKey := string(utils.ReadFile(flags.SSL.Proxy.Key))

// Handle intermediate CAs
var intermediateCAs []string
for _, path := range flags.Ssl.Ca.Intermediate {
for _, path := range flags.SSL.Ca.Intermediate {
intermediateCAs = append(intermediateCAs, string(utils.ReadFile(path)))
}

Expand Down Expand Up @@ -111,13 +111,13 @@ func handleProxyConfigGenerate(
proxyConfigGenerate func(client *api.APIClient, request proxy.ProxyConfigGenerateRequest) (*[]int8, error),
) (*[]int8, error) {
// CA key and password
caKey := string(utils.ReadFile(flags.Ssl.Ca.Key))
caKey := string(utils.ReadFile(flags.SSL.Ca.Key))

var caPasswordRead string
if flags.Ssl.Ca.Password == "" {
if flags.SSL.Ca.Password == "" {
utils.AskPasswordIfMissingOnce(&caPasswordRead, L("Please enter SSL CA password"), 0, 0)
} else {
caPasswordRead = flags.Ssl.Ca.Password
caPasswordRead = flags.SSL.Ca.Password
}

// Prepare the request object & call the proxyConfigGenerate function
Expand All @@ -130,13 +130,13 @@ func handleProxyConfigGenerate(
CaCrt: caCertificate,
CaKey: caKey,
CaPassword: caPasswordRead,
Cnames: flags.Ssl.Cnames,
Country: flags.Ssl.Country,
State: flags.Ssl.State,
City: flags.Ssl.City,
Org: flags.Ssl.Org,
OrgUnit: flags.Ssl.OU,
SslEmail: flags.Ssl.Email,
Cnames: flags.SSL.Cnames,
Country: flags.SSL.Country,
State: flags.SSL.State,
City: flags.SSL.City,
Org: flags.SSL.Org,
OrgUnit: flags.SSL.OU,
SSLEmail: flags.SSL.Email,
}

return proxyConfigGenerate(client, request)
Expand Down
Loading

0 comments on commit 33f0111

Please sign in to comment.