-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: kshamajain99 <[email protected]>
- Loading branch information
1 parent
64e1c38
commit dacf04c
Showing
20 changed files
with
407 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
controller: sh -c "FORCE_LOG_COLORS=1 ARGOCD_FAKE_IN_CLUSTER=true ARGOCD_TLS_DATA_PATH=${ARGOCD_TLS_DATA_PATH:-/tmp/argocd-local/tls} ARGOCD_SSH_DATA_PATH=${ARGOCD_SSH_DATA_PATH:-/tmp/argocd-local/ssh} go run ./cmd/argocd-application-controller/main.go --loglevel debug --redis localhost:${ARGOCD_E2E_REDIS_PORT:-6379} --repo-server localhost:${ARGOCD_E2E_REPOSERVER_PORT:-8081}" | ||
api-server: sh -c "FORCE_LOG_COLORS=1 ARGOCD_FAKE_IN_CLUSTER=true ARGOCD_TLS_DATA_PATH=${ARGOCD_TLS_DATA_PATH:-/tmp/argocd-local/tls} ARGOCD_SSH_DATA_PATH=${ARGOCD_SSH_DATA_PATH:-/tmp/argocd-local/ssh} go run ./cmd/argocd-server/main.go --loglevel debug --redis localhost:${ARGOCD_E2E_REDIS_PORT:-6379} --disable-auth=${ARGOCD_E2E_DISABLE_AUTH:-'true'} --insecure --dex-server http://localhost:${ARGOCD_E2E_DEX_PORT:-5556} --repo-server localhost:${ARGOCD_E2E_REPOSERVER_PORT:-8081} --port ${ARGOCD_E2E_APISERVER_PORT:-8080} --staticassets ui/dist/app" | ||
dex: sh -c "go run github.com/argoproj/argo-cd/cmd/argocd-util gendexcfg -o `pwd`/dist/dex.yaml && docker run --rm -p ${ARGOCD_E2E_DEX_PORT:-5556}:${ARGOCD_E2E_DEX_PORT:-5556} -v `pwd`/dist/dex.yaml:/dex.yaml ghcr.io/dexidp/dex:v2.27.0 serve /dex.yaml" | ||
controller: sh -c "FORCE_LOG_COLORS=1 ARGOCD_FAKE_IN_CLUSTER=true ARGOCD_TLS_DATA_PATH=${ARGOCD_TLS_DATA_PATH:-/tmp/argocd-local/tls} ARGOCD_SSH_DATA_PATH=${ARGOCD_SSH_DATA_PATH:-/tmp/argocd-local/ssh} ARGOCD_BINARY_NAME=argocd-application-controller go run ./cmd/main.go --loglevel debug --redis localhost:${ARGOCD_E2E_REDIS_PORT:-6379} --repo-server localhost:${ARGOCD_E2E_REPOSERVER_PORT:-8081}" | ||
api-server: sh -c "FORCE_LOG_COLORS=1 ARGOCD_FAKE_IN_CLUSTER=true ARGOCD_TLS_DATA_PATH=${ARGOCD_TLS_DATA_PATH:-/tmp/argocd-local/tls} ARGOCD_SSH_DATA_PATH=${ARGOCD_SSH_DATA_PATH:-/tmp/argocd-local/ssh} ARGOCD_BINARY_NAME=argocd-server go run ./cmd/main.go --loglevel debug --redis localhost:${ARGOCD_E2E_REDIS_PORT:-6379} --disable-auth=${ARGOCD_E2E_DISABLE_AUTH:-'true'} --insecure --dex-server http://localhost:${ARGOCD_E2E_DEX_PORT:-5556} --repo-server localhost:${ARGOCD_E2E_REPOSERVER_PORT:-8081} --port ${ARGOCD_E2E_APISERVER_PORT:-8080} --staticassets ui/dist/app" | ||
dex: sh -c "ARGOCD_BINARY_NAME=argocd-dex go run github.com/argoproj/argo-cd/cmd gendexcfg -o `pwd`/dist/dex.yaml && docker run --rm -p ${ARGOCD_E2E_DEX_PORT:-5556}:${ARGOCD_E2E_DEX_PORT:-5556} -v `pwd`/dist/dex.yaml:/dex.yaml ghcr.io/dexidp/dex:v2.27.0 serve /dex.yaml" | ||
redis: docker run --rm --name argocd-redis -i -p ${ARGOCD_E2E_REDIS_PORT:-6379}:${ARGOCD_E2E_REDIS_PORT:-6379} redis:5.0.10-alpine --save "" --appendonly no --port ${ARGOCD_E2E_REDIS_PORT:-6379} | ||
repo-server: sh -c "FORCE_LOG_COLORS=1 ARGOCD_FAKE_IN_CLUSTER=true ARGOCD_GNUPGHOME=${ARGOCD_GNUPGHOME:-/tmp/argocd-local/gpg/keys} ARGOCD_GPG_DATA_PATH=${ARGOCD_GPG_DATA_PATH:-/tmp/argocd-local/gpg/source} ARGOCD_TLS_DATA_PATH=${ARGOCD_TLS_DATA_PATH:-/tmp/argocd-local/tls} ARGOCD_SSH_DATA_PATH=${ARGOCD_SSH_DATA_PATH:-/tmp/argocd-local/ssh} go run ./cmd/argocd-repo-server/main.go --loglevel debug --port ${ARGOCD_E2E_REPOSERVER_PORT:-8081} --redis localhost:${ARGOCD_E2E_REDIS_PORT:-6379}" | ||
repo-server: sh -c "FORCE_LOG_COLORS=1 ARGOCD_FAKE_IN_CLUSTER=true ARGOCD_GNUPGHOME=${ARGOCD_GNUPGHOME:-/tmp/argocd-local/gpg/keys} ARGOCD_GPG_DATA_PATH=${ARGOCD_GPG_DATA_PATH:-/tmp/argocd-local/gpg/source} ARGOCD_TLS_DATA_PATH=${ARGOCD_TLS_DATA_PATH:-/tmp/argocd-local/tls} ARGOCD_SSH_DATA_PATH=${ARGOCD_SSH_DATA_PATH:-/tmp/argocd-local/ssh} ARGOCD_BINARY_NAME=argocd-repo-server go run ./cmd/main.go --loglevel debug --port ${ARGOCD_E2E_REPOSERVER_PORT:-8081} --redis localhost:${ARGOCD_E2E_REDIS_PORT:-6379}" | ||
ui: sh -c 'cd ui && ${ARGOCD_E2E_YARN_CMD:-yarn} start' | ||
git-server: test/fixture/testrepos/start-git.sh | ||
dev-mounter: [[ "$ARGOCD_E2E_TEST" != "true" ]] && go run hack/dev-mounter/main.go --configmap argocd-ssh-known-hosts-cm=${ARGOCD_SSH_DATA_PATH:-/tmp/argocd-local/ssh} --configmap argocd-tls-certs-cm=${ARGOCD_TLS_DATA_PATH:-/tmp/argocd-local/tls} --configmap argocd-gpg-keys-cm=${ARGOCD_GPG_DATA_PATH:-/tmp/argocd-local/gpg/source} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,206 @@ | ||
package commands | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
"os/exec" | ||
"syscall" | ||
|
||
"github.com/ghodss/yaml" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
"k8s.io/client-go/kubernetes" | ||
"k8s.io/client-go/tools/clientcmd" | ||
|
||
"github.com/argoproj/argo-cd/util/cli" | ||
"github.com/argoproj/argo-cd/util/dex" | ||
"github.com/argoproj/argo-cd/util/errors" | ||
"github.com/argoproj/argo-cd/util/settings" | ||
) | ||
|
||
const ( | ||
cliName = "argocd-dex" | ||
) | ||
|
||
func NewCommand() *cobra.Command { | ||
var ( | ||
logFormat string | ||
logLevel string | ||
) | ||
|
||
var command = &cobra.Command{ | ||
Use: cliName, | ||
Short: "argocd-util tools used by Argo CD", | ||
Long: "argocd-util has internal utility tools used by Argo CD", | ||
DisableAutoGenTag: true, | ||
Run: func(c *cobra.Command, args []string) { | ||
c.HelpFunc()(c, args) | ||
}, | ||
} | ||
|
||
command.AddCommand(NewRunDexCommand()) | ||
command.AddCommand(NewGenDexConfigCommand()) | ||
|
||
command.Flags().StringVar(&logFormat, "logformat", "text", "Set the logging format. One of: text|json") | ||
command.Flags().StringVar(&logLevel, "loglevel", "info", "Set the logging level. One of: debug|info|warn|error") | ||
return command | ||
} | ||
|
||
func NewRunDexCommand() *cobra.Command { | ||
var ( | ||
clientConfig clientcmd.ClientConfig | ||
) | ||
var command = cobra.Command{ | ||
Use: "rundex", | ||
Short: "Runs dex generating a config using settings from the Argo CD configmap and secret", | ||
RunE: func(c *cobra.Command, args []string) error { | ||
_, err := exec.LookPath("dex") | ||
errors.CheckError(err) | ||
config, err := clientConfig.ClientConfig() | ||
errors.CheckError(err) | ||
namespace, _, err := clientConfig.Namespace() | ||
errors.CheckError(err) | ||
kubeClientset := kubernetes.NewForConfigOrDie(config) | ||
settingsMgr := settings.NewSettingsManager(context.Background(), kubeClientset, namespace) | ||
prevSettings, err := settingsMgr.GetSettings() | ||
errors.CheckError(err) | ||
updateCh := make(chan *settings.ArgoCDSettings, 1) | ||
settingsMgr.Subscribe(updateCh) | ||
|
||
for { | ||
var cmd *exec.Cmd | ||
dexCfgBytes, err := dex.GenerateDexConfigYAML(prevSettings) | ||
errors.CheckError(err) | ||
if len(dexCfgBytes) == 0 { | ||
log.Infof("dex is not configured") | ||
} else { | ||
err = ioutil.WriteFile("/tmp/dex.yaml", dexCfgBytes, 0644) | ||
errors.CheckError(err) | ||
log.Debug(redactor(string(dexCfgBytes))) | ||
cmd = exec.Command("dex", "serve", "/tmp/dex.yaml") | ||
cmd.Stdout = os.Stdout | ||
cmd.Stderr = os.Stderr | ||
err = cmd.Start() | ||
errors.CheckError(err) | ||
} | ||
|
||
// loop until the dex config changes | ||
for { | ||
newSettings := <-updateCh | ||
newDexCfgBytes, err := dex.GenerateDexConfigYAML(newSettings) | ||
errors.CheckError(err) | ||
if string(newDexCfgBytes) != string(dexCfgBytes) { | ||
prevSettings = newSettings | ||
log.Infof("dex config modified. restarting dex") | ||
if cmd != nil && cmd.Process != nil { | ||
err = cmd.Process.Signal(syscall.SIGTERM) | ||
errors.CheckError(err) | ||
_, err = cmd.Process.Wait() | ||
errors.CheckError(err) | ||
} | ||
break | ||
} else { | ||
log.Infof("dex config unmodified") | ||
} | ||
} | ||
} | ||
}, | ||
} | ||
|
||
clientConfig = cli.AddKubectlFlagsToCmd(&command) | ||
return &command | ||
} | ||
|
||
func NewGenDexConfigCommand() *cobra.Command { | ||
var ( | ||
clientConfig clientcmd.ClientConfig | ||
out string | ||
) | ||
var command = cobra.Command{ | ||
Use: "gendexcfg", | ||
Short: "Generates a dex config from Argo CD settings", | ||
RunE: func(c *cobra.Command, args []string) error { | ||
config, err := clientConfig.ClientConfig() | ||
errors.CheckError(err) | ||
namespace, _, err := clientConfig.Namespace() | ||
errors.CheckError(err) | ||
kubeClientset := kubernetes.NewForConfigOrDie(config) | ||
settingsMgr := settings.NewSettingsManager(context.Background(), kubeClientset, namespace) | ||
settings, err := settingsMgr.GetSettings() | ||
errors.CheckError(err) | ||
dexCfgBytes, err := dex.GenerateDexConfigYAML(settings) | ||
errors.CheckError(err) | ||
if len(dexCfgBytes) == 0 { | ||
log.Infof("dex is not configured") | ||
return nil | ||
} | ||
if out == "" { | ||
dexCfg := make(map[string]interface{}) | ||
err := yaml.Unmarshal(dexCfgBytes, &dexCfg) | ||
errors.CheckError(err) | ||
if staticClientsInterface, ok := dexCfg["staticClients"]; ok { | ||
if staticClients, ok := staticClientsInterface.([]interface{}); ok { | ||
for i := range staticClients { | ||
staticClient := staticClients[i] | ||
if mappings, ok := staticClient.(map[string]interface{}); ok { | ||
for key := range mappings { | ||
if key == "secret" { | ||
mappings[key] = "******" | ||
} | ||
} | ||
staticClients[i] = mappings | ||
} | ||
} | ||
dexCfg["staticClients"] = staticClients | ||
} | ||
} | ||
errors.CheckError(err) | ||
maskedDexCfgBytes, err := yaml.Marshal(dexCfg) | ||
errors.CheckError(err) | ||
fmt.Print(string(maskedDexCfgBytes)) | ||
} else { | ||
err = ioutil.WriteFile(out, dexCfgBytes, 0644) | ||
errors.CheckError(err) | ||
} | ||
return nil | ||
}, | ||
} | ||
|
||
clientConfig = cli.AddKubectlFlagsToCmd(&command) | ||
command.Flags().StringVarP(&out, "out", "o", "", "Output to the specified file instead of stdout") | ||
return &command | ||
} | ||
|
||
func iterateStringFields(obj interface{}, callback func(name string, val string) string) { | ||
if mapField, ok := obj.(map[string]interface{}); ok { | ||
for field, val := range mapField { | ||
if strVal, ok := val.(string); ok { | ||
mapField[field] = callback(field, strVal) | ||
} else { | ||
iterateStringFields(val, callback) | ||
} | ||
} | ||
} else if arrayField, ok := obj.([]interface{}); ok { | ||
for i := range arrayField { | ||
iterateStringFields(arrayField[i], callback) | ||
} | ||
} | ||
} | ||
|
||
func redactor(dirtyString string) string { | ||
config := make(map[string]interface{}) | ||
err := yaml.Unmarshal([]byte(dirtyString), &config) | ||
errors.CheckError(err) | ||
iterateStringFields(config, func(name string, val string) string { | ||
if name == "clientSecret" || name == "secret" || name == "bindPW" { | ||
return "********" | ||
} else { | ||
return val | ||
} | ||
}) | ||
data, err := yaml.Marshal(config) | ||
errors.CheckError(err) | ||
return string(data) | ||
} |
Oops, something went wrong.