2018-02-20 22:06:15 +00:00
package common
2020-03-18 10:28:31 +00:00
import (
2024-07-15 19:09:49 +00:00
"context"
2024-12-21 10:36:46 +00:00
"errors"
2024-07-15 19:09:49 +00:00
"fmt"
2026-02-26 15:07:00 +00:00
"math"
2020-03-18 10:28:31 +00:00
"os"
2022-03-15 19:06:21 +00:00
"path/filepath"
"strconv"
2020-03-29 08:35:25 +00:00
"time"
2022-03-15 19:06:21 +00:00
2024-07-15 19:09:49 +00:00
"github.com/redis/go-redis/v9"
2022-03-15 19:06:21 +00:00
"github.com/sirupsen/logrus"
2023-02-16 14:07:57 +00:00
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
2024-12-31 08:34:11 +00:00
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2024-07-15 19:09:49 +00:00
"k8s.io/client-go/kubernetes"
2026-02-26 15:07:00 +00:00
"github.com/argoproj/argo-cd/v3/util/env"
2020-03-18 10:28:31 +00:00
)
2026-02-15 11:03:39 +00:00
// Argo CD component names
2023-09-22 19:49:09 +00:00
const (
2026-02-15 11:03:39 +00:00
CommandCLI = "argocd"
CommandApplicationController = "argocd-application-controller"
CommandApplicationSetController = "argocd-applicationset-controller"
CommandServer = "argocd-server"
CommandCMPServer = "argocd-cmp-server"
CommandCommitServer = "argocd-commit-server"
CommandGitAskPass = "argocd-git-ask-pass"
CommandNotifications = "argocd-notifications"
CommandK8sAuth = "argocd-k8s-auth"
CommandDex = "argocd-dex"
CommandRepoServer = "argocd-repo-server"
2023-09-22 19:49:09 +00:00
)
2018-12-01 07:54:01 +00:00
// Default service addresses and URLS of Argo CD internal services
2018-02-20 22:06:15 +00:00
const (
2018-12-01 07:54:01 +00:00
// DefaultRepoServerAddr is the gRPC address of the Argo CD repo server
DefaultRepoServerAddr = "argocd-repo-server:8081"
2024-12-16 21:59:09 +00:00
// DefaultCommitServerAddr is the gRPC address of the Argo CD commit server
DefaultCommitServerAddr = "argocd-commit-server:8086"
2018-12-01 07:54:01 +00:00
// DefaultDexServerAddr is the HTTP address of the Dex OIDC server, which we run a reverse proxy against
2022-07-13 20:45:35 +00:00
DefaultDexServerAddr = "argocd-dex-server:5556"
2019-02-13 23:20:40 +00:00
// DefaultRedisAddr is the default redis address
2019-02-19 17:23:05 +00:00
DefaultRedisAddr = "argocd-redis:6379"
2018-11-18 00:00:55 +00:00
)
2018-12-01 07:54:01 +00:00
// Kubernetes ConfigMap and Secret resource names which hold Argo CD settings
2018-04-04 11:11:20 +00:00
const (
2022-08-25 23:04:14 +00:00
ArgoCDConfigMapName = "argocd-cm"
ArgoCDSecretName = "argocd-secret"
ArgoCDNotificationsConfigMapName = "argocd-notifications-cm"
ArgoCDNotificationsSecretName = "argocd-notifications-secret"
ArgoCDRBACConfigMapName = "argocd-rbac-cm"
2023-03-29 19:41:22 +00:00
// ArgoCDKnownHostsConfigMapName contains SSH known hosts data for connecting repositories. Will get mounted as volume to pods
2019-07-11 23:00:47 +00:00
ArgoCDKnownHostsConfigMapName = "argocd-ssh-known-hosts-cm"
2023-03-29 19:41:22 +00:00
// ArgoCDTLSCertsConfigMapName contains TLS certificate data for connecting repositories. Will get mounted as volume to pods
2019-07-11 23:00:47 +00:00
ArgoCDTLSCertsConfigMapName = "argocd-tls-certs-cm"
2020-06-22 16:21:53 +00:00
ArgoCDGPGKeysConfigMapName = "argocd-gpg-keys-cm"
2023-09-22 19:49:09 +00:00
// ArgoCDAppControllerShardConfigMapName contains the application controller to shard mapping
ArgoCDAppControllerShardConfigMapName = "argocd-app-controller-shard-cm"
2024-08-13 17:30:00 +00:00
ArgoCDCmdParamsConfigMapName = "argocd-cmd-params-cm"
2018-04-04 11:11:20 +00:00
)
2019-11-04 04:15:28 +00:00
// Some default configurables
2019-06-03 16:50:46 +00:00
const (
DefaultSystemNamespace = "kube-system"
2019-11-04 04:15:28 +00:00
DefaultRepoType = "git"
2019-06-03 16:50:46 +00:00
)
2019-05-28 18:41:02 +00:00
// Default listener ports for ArgoCD components
2019-02-22 23:20:34 +00:00
const (
2019-05-28 18:41:02 +00:00
DefaultPortAPIServer = 8080
DefaultPortRepoServer = 8081
DefaultPortArgoCDMetrics = 8082
DefaultPortArgoCDAPIServerMetrics = 8083
DefaultPortRepoServerMetrics = 8084
2024-12-16 21:59:09 +00:00
DefaultPortCommitServer = 8086
DefaultPortCommitServerMetrics = 8087
2019-02-22 23:20:34 +00:00
)
2023-03-29 19:41:22 +00:00
// DefaultAddressAPIServer for ArgoCD components
2022-01-07 07:25:38 +00:00
const (
2024-12-16 21:59:09 +00:00
DefaultAddressAdminDashboard = "localhost"
DefaultAddressAPIServer = "0.0.0.0"
DefaultAddressAPIServerMetrics = "0.0.0.0"
DefaultAddressRepoServer = "0.0.0.0"
DefaultAddressRepoServerMetrics = "0.0.0.0"
DefaultAddressCommitServer = "0.0.0.0"
DefaultAddressCommitServerMetrics = "0.0.0.0"
2022-01-07 07:25:38 +00:00
)
2019-07-25 00:25:27 +00:00
// Default paths on the pod's file system
const (
2023-03-29 19:41:22 +00:00
// DefaultPathTLSConfig is the default path where TLS certificates for repositories are located
2019-07-25 00:25:27 +00:00
DefaultPathTLSConfig = "/app/config/tls"
2023-03-29 19:41:22 +00:00
// DefaultPathSSHConfig is the default path where SSH known hosts are stored
2019-07-25 00:25:27 +00:00
DefaultPathSSHConfig = "/app/config/ssh"
2023-03-29 19:41:22 +00:00
// DefaultSSHKnownHostsName is the Default name for the SSH known hosts file
2019-07-25 00:25:27 +00:00
DefaultSSHKnownHostsName = "ssh_known_hosts"
2023-03-29 19:41:22 +00:00
// DefaultGnuPgHomePath is the Default path to GnuPG home directory
2020-06-22 16:21:53 +00:00
DefaultGnuPgHomePath = "/app/config/gpg/keys"
2023-03-29 19:41:22 +00:00
// DefaultAppConfigPath is the Default path to repo server TLS endpoint config
2021-03-16 16:23:10 +00:00
DefaultAppConfigPath = "/app/config"
2023-03-29 19:41:22 +00:00
// DefaultPluginSockFilePath is the Default path to cmp server plugin socket file
2021-11-08 17:47:10 +00:00
DefaultPluginSockFilePath = "/home/argocd/cmp-server/plugins"
2023-03-29 19:41:22 +00:00
// DefaultPluginConfigFilePath is the Default path to cmp server plugin configuration file
2021-11-08 17:47:10 +00:00
DefaultPluginConfigFilePath = "/home/argocd/cmp-server/config"
2023-03-29 19:41:22 +00:00
// PluginConfigFileName is the Plugin Config File is a ConfigManagementPlugin manifest located inside the plugin container
2021-11-08 17:47:10 +00:00
PluginConfigFileName = "plugin.yaml"
2019-07-25 00:25:27 +00:00
)
2025-07-31 16:55:12 +00:00
// consts for podrequests metrics in cache/info
const (
PodRequestsCPU = "cpu"
PodRequestsMEM = "memory"
)
2018-12-01 07:54:01 +00:00
// Argo CD application related constants
const (
// ArgoCDAdminUsername is the username of the 'admin' user
ArgoCDAdminUsername = "admin"
// ArgoCDUserAgentName is the default user-agent name used by the gRPC API client library and grpc-gateway
ArgoCDUserAgentName = "argocd-client"
2022-08-05 23:16:35 +00:00
// ArgoCDSSAManager is the default argocd manager name used by server-side apply syncs
ArgoCDSSAManager = "argocd-controller"
2018-12-01 07:54:01 +00:00
// AuthCookieName is the HTTP cookie name where we store our auth token
AuthCookieName = "argocd.token"
2022-01-26 18:59:50 +00:00
// StateCookieName is the HTTP cookie name that holds temporary nonce tokens for CSRF protection
StateCookieName = "argocd.oauthstate"
// StateCookieMaxAge is the maximum age of the oauth state cookie
StateCookieMaxAge = time . Minute * 5
2021-05-19 19:43:04 +00:00
2020-03-29 08:35:25 +00:00
// ChangePasswordSSOTokenMaxAge is the max token age for password change operation
ChangePasswordSSOTokenMaxAge = time . Minute * 5
2021-02-19 22:24:32 +00:00
// GithubAppCredsExpirationDuration is the default time used to cache the GitHub app credentials
GithubAppCredsExpirationDuration = time . Minute * 60
2026-04-16 15:16:47 +00:00
// AzureServicePrincipalCredsExpirationDuration is the default time used to cache the Azure service principal credentials
// SP tokens are valid for 60 minutes, so cache for 59 minutes to avoid issues with token expiration when taking the cleanup interval of 1 minute into account
AzureServicePrincipalCredsExpirationDuration = time . Minute * 59
2021-08-25 06:21:03 +00:00
// PasswordPatten is the default password patten
PasswordPatten = ` ^. { 8,32}$ `
2023-06-05 13:19:14 +00:00
2023-06-21 01:32:14 +00:00
// LegacyShardingAlgorithm is the default value for Sharding Algorithm it uses an `uid` based distribution (non-uniform)
2023-06-05 13:19:14 +00:00
LegacyShardingAlgorithm = "legacy"
2024-05-28 09:51:04 +00:00
// RoundRobinShardingAlgorithm is a flag value that can be opted for Sharding Algorithm it uses an equal distribution across all shards
2023-06-05 13:19:14 +00:00
RoundRobinShardingAlgorithm = "round-robin"
2023-09-22 19:49:09 +00:00
// AppControllerHeartbeatUpdateRetryCount is the retry count for updating the Shard Mapping to the Shard Mapping ConfigMap used by Application Controller
AppControllerHeartbeatUpdateRetryCount = 3
2024-06-05 18:28:19 +00:00
// ConsistentHashingWithBoundedLoadsAlgorithm uses an algorithm that tries to use an equal distribution across
// all shards but is optimised to handle sharding and/or cluster addition or removal. In case of sharding or
// cluster changes, this algorithm minimises the changes between shard and clusters assignments.
ConsistentHashingWithBoundedLoadsAlgorithm = "consistent-hashing"
DefaultShardingAlgorithm = LegacyShardingAlgorithm
2018-12-01 07:54:01 +00:00
)
// Dex related constants
2018-05-10 22:43:58 +00:00
const (
// DexAPIEndpoint is the endpoint where we serve the Dex API server
DexAPIEndpoint = "/api/dex"
2018-11-05 19:29:01 +00:00
// LoginEndpoint is Argo CD's shorthand login endpoint which redirects to dex's OAuth 2.0 provider's consent page
2018-05-10 22:43:58 +00:00
LoginEndpoint = "/auth/login"
2020-11-20 19:19:17 +00:00
// LogoutEndpoint is Argo CD's shorthand logout endpoint which invalidates OIDC session after logout
LogoutEndpoint = "/auth/logout"
2018-11-05 19:29:01 +00:00
// CallbackEndpoint is Argo CD's final callback endpoint we reach after OAuth 2.0 login flow has been completed
2018-05-10 22:43:58 +00:00
CallbackEndpoint = "/auth/callback"
2019-08-23 21:06:20 +00:00
// DexCallbackEndpoint is Argo CD's final callback endpoint when Dex is configured
DexCallbackEndpoint = "/api/dex/callback"
2018-05-10 22:43:58 +00:00
// ArgoCDClientAppName is name of the Oauth client app used when registering our web app to dex
2018-11-05 19:29:01 +00:00
ArgoCDClientAppName = "Argo CD"
2018-05-10 22:43:58 +00:00
// ArgoCDClientAppID is the Oauth client ID we will use when registering our app to dex
ArgoCDClientAppID = "argo-cd"
// ArgoCDCLIClientAppName is name of the Oauth client app used when registering our CLI to dex
2018-11-05 19:29:01 +00:00
ArgoCDCLIClientAppName = "Argo CD CLI"
2018-05-10 22:43:58 +00:00
// ArgoCDCLIClientAppID is the Oauth client ID we will use when registering our CLI to dex
ArgoCDCLIClientAppID = "argo-cd-cli"
2025-01-31 17:12:59 +00:00
// DexFederatedScope allows to receive the federated_claims from Dex. https://dexidp.io/docs/configuration/custom-scopes-claims-clients/
DexFederatedScope = "federated:id"
2018-05-10 22:43:58 +00:00
)
2018-12-01 07:54:01 +00:00
// Resource metadata labels and annotations (keys and values) used by Argo CD components
const (
// LabelKeyAppInstance is the label key to use to uniquely identify the instance of an application
// The Argo CD application name is used as the instance name
LabelKeyAppInstance = "app.kubernetes.io/instance"
2023-08-22 19:29:13 +00:00
// LabelKeyAppName is the label key to use to uniquely identify the name of the Kubernetes application
LabelKeyAppName = "app.kubernetes.io/name"
2024-03-01 20:18:19 +00:00
// LabelKeyAutoLabelClusterInfo if set to true will automatically add extra labels from the cluster info (currently it only adds a k8s version label)
LabelKeyAutoLabelClusterInfo = "argocd.argoproj.io/auto-label-cluster-info"
2021-07-13 17:02:03 +00:00
// LabelKeyLegacyApplicationName is the legacy label (v0.10 and below) and is superseded by 'app.kubernetes.io/instance'
2018-12-01 07:54:01 +00:00
LabelKeyLegacyApplicationName = "applications.argoproj.io/app-name"
2021-06-23 17:46:43 +00:00
// LabelKeySecretType contains the type of argocd secret (currently: 'cluster', 'repository', 'repo-config' or 'repo-creds')
2018-12-01 07:54:01 +00:00
LabelKeySecretType = "argocd.argoproj.io/secret-type"
2024-03-01 20:18:19 +00:00
// LabelKeyClusterKubernetesVersion contains the kubernetes version of the cluster secret if it has been enabled
LabelKeyClusterKubernetesVersion = "argocd.argoproj.io/kubernetes-version"
2018-12-01 07:54:01 +00:00
// LabelValueSecretTypeCluster indicates a secret type of cluster
LabelValueSecretTypeCluster = "cluster"
2021-06-23 17:46:43 +00:00
// LabelValueSecretTypeRepository indicates a secret type of repository
LabelValueSecretTypeRepository = "repository"
// LabelValueSecretTypeRepoCreds indicates a secret type of repository credentials
LabelValueSecretTypeRepoCreds = "repo-creds"
2024-12-16 21:59:09 +00:00
// LabelValueSecretTypeRepositoryWrite indicates a secret type of repository credentials for writing
LabelValueSecretTypeRepositoryWrite = "repository-write"
2025-08-27 14:13:42 +00:00
// LabelValueSecretTypeRepoCredsWrite indicates a secret type of repository credentials for writing for templating
LabelValueSecretTypeRepoCredsWrite = "repo-write-creds"
2024-10-15 12:28:13 +00:00
// LabelValueSecretTypeSCMCreds indicates a secret type of SCM credentials
LabelValueSecretTypeSCMCreds = "scm-creds"
2018-12-01 07:54:01 +00:00
2023-03-29 19:41:22 +00:00
// AnnotationKeyAppInstance is the Argo CD application name is used as the instance name
2021-10-04 16:48:51 +00:00
AnnotationKeyAppInstance = "argocd.argoproj.io/tracking-id"
2024-10-05 00:54:37 +00:00
AnnotationInstallationID = "argocd.argoproj.io/installation-id"
2021-10-04 16:48:51 +00:00
2019-06-07 15:46:11 +00:00
// AnnotationCompareOptions is a comma-separated list of options for comparison
AnnotationCompareOptions = "argocd.argoproj.io/compare-options"
2020-05-15 17:01:18 +00:00
2025-06-13 21:58:07 +00:00
// AnnotationClientSideApplyMigrationManager specifies a custom field manager for client-side apply migration
AnnotationClientSideApplyMigrationManager = "argocd.argoproj.io/client-side-apply-migration-manager"
2024-11-21 12:16:53 +00:00
// AnnotationIgnoreHealthCheck when set on an Application's immediate child indicates that its health check
// can be disregarded.
AnnotationIgnoreHealthCheck = "argocd.argoproj.io/ignore-healthcheck"
2018-12-01 07:54:01 +00:00
// AnnotationKeyManagedBy is annotation name which indicates that k8s resource is managed by an application.
AnnotationKeyManagedBy = "managed-by"
// AnnotationValueManagedByArgoCD is a 'managed-by' annotation value for resources managed by Argo CD
AnnotationValueManagedByArgoCD = "argocd.argoproj.io"
2020-10-29 20:17:54 +00:00
2020-09-30 05:39:10 +00:00
// AnnotationKeyLinkPrefix tells the UI to add an external link icon to the application node
// that links to the value given in the annotation.
// The annotation key must be followed by a unique identifier. Ex: link.argocd.argoproj.io/dashboard
2020-10-20 01:21:06 +00:00
// It's valid to have multiple annotations that match the prefix.
2020-09-30 05:39:10 +00:00
// Values can simply be a url or they can have
// an optional link title separated by a "|"
// Ex: "http://grafana.example.com/d/yu5UH4MMz/deployments"
// Ex: "Go to Dashboard|http://grafana.example.com/d/yu5UH4MMz/deployments"
AnnotationKeyLinkPrefix = "link.argocd.argoproj.io/"
2025-12-02 10:04:58 +00:00
// AnnotationKeyIgnoreDefaultLinks tells the Application to not add autogenerated links from this object into its externalURLs
// This applies to ingress objects and takes effect if set to "true"
// This only disables the default behavior of generating links based on the ingress spec, and does not disable AnnotationKeyLinkPrefix
AnnotationKeyIgnoreDefaultLinks = "argocd.argoproj.io/ignore-default-links"
2023-02-23 17:02:50 +00:00
// AnnotationKeyAppSkipReconcile tells the Application to skip the Application controller reconcile.
// Skip reconcile when the value is "true" or any other string values that can be strconv.ParseBool() to be true.
AnnotationKeyAppSkipReconcile = "argocd.argoproj.io/skip-reconcile"
2025-10-15 01:38:14 +00:00
2024-03-29 18:49:16 +00:00
// LabelKeyComponentRepoServer is the label key to identify the component as repo-server
LabelKeyComponentRepoServer = "app.kubernetes.io/component"
// LabelValueComponentRepoServer is the label value for the repo-server component
LabelValueComponentRepoServer = "repo-server"
2018-02-20 22:06:15 +00:00
)
2018-02-27 11:08:19 +00:00
2018-12-01 07:54:01 +00:00
// Environment variables for tuning and debugging Argo CD
2018-02-27 11:08:19 +00:00
const (
2018-12-01 07:54:01 +00:00
// EnvVarSSODebug is an environment variable to enable additional OAuth debugging in the API server
EnvVarSSODebug = "ARGOCD_SSO_DEBUG"
// EnvVarRBACDebug is an environment variable to enable additional RBAC debugging in the API server
EnvVarRBACDebug = "ARGOCD_RBAC_DEBUG"
2023-03-29 19:41:22 +00:00
// EnvVarSSHDataPath overrides the location where SSH known hosts for repo access data is stored
2019-07-25 00:25:27 +00:00
EnvVarSSHDataPath = "ARGOCD_SSH_DATA_PATH"
2023-03-29 19:41:22 +00:00
// EnvVarTLSDataPath overrides the location where TLS certificate for repo access data is stored
2019-07-25 00:25:27 +00:00
EnvVarTLSDataPath = "ARGOCD_TLS_DATA_PATH"
2023-03-29 19:41:22 +00:00
// EnvGitAttemptsCount specifies number of git remote operations attempts count
2019-09-11 05:03:21 +00:00
EnvGitAttemptsCount = "ARGOCD_GIT_ATTEMPTS_COUNT"
2024-05-28 09:51:04 +00:00
// EnvGitRetryMaxDuration specifies max duration of git remote operation retry
2021-10-08 21:00:09 +00:00
EnvGitRetryMaxDuration = "ARGOCD_GIT_RETRY_MAX_DURATION"
2023-03-29 19:41:22 +00:00
// EnvGitRetryDuration specifies duration of git remote operation retry
2021-10-08 21:00:09 +00:00
EnvGitRetryDuration = "ARGOCD_GIT_RETRY_DURATION"
2024-08-17 19:16:04 +00:00
// EnvGitRetryFactor specifies factor of git remote operation retry
2021-10-08 21:00:09 +00:00
EnvGitRetryFactor = "ARGOCD_GIT_RETRY_FACTOR"
2023-03-29 19:41:22 +00:00
// EnvGitSubmoduleEnabled overrides git submodule support, true by default
2019-10-21 22:17:07 +00:00
EnvGitSubmoduleEnabled = "ARGOCD_GIT_MODULES_ENABLED"
2026-01-19 17:06:09 +00:00
// EnvHelmUserAgent specifies the User-Agent header for Helm repository requests
EnvHelmUserAgent = "ARGOCD_HELM_USER_AGENT"
2020-06-22 16:21:53 +00:00
// EnvGnuPGHome is the path to ArgoCD's GnuPG keyring for signature verification
EnvGnuPGHome = "ARGOCD_GNUPGHOME"
2020-09-17 23:21:25 +00:00
// EnvWatchAPIBufferSize is the buffer size used to transfer K8S watch events to watch API consumer
EnvWatchAPIBufferSize = "ARGOCD_WATCH_API_BUFFER_SIZE"
2020-10-09 20:47:31 +00:00
// EnvPauseGenerationAfterFailedAttempts will pause manifest generation after the specified number of failed generation attempts
EnvPauseGenerationAfterFailedAttempts = "ARGOCD_PAUSE_GEN_AFTER_FAILED_ATTEMPTS"
// EnvPauseGenerationMinutes pauses manifest generation for the specified number of minutes, after sufficient manifest generation failures
EnvPauseGenerationMinutes = "ARGOCD_PAUSE_GEN_MINUTES"
// EnvPauseGenerationRequests pauses manifest generation for the specified number of requests, after sufficient manifest generation failures
EnvPauseGenerationRequests = "ARGOCD_PAUSE_GEN_REQUESTS"
2020-10-09 20:16:54 +00:00
// EnvControllerReplicas is the number of controller replicas
EnvControllerReplicas = "ARGOCD_CONTROLLER_REPLICAS"
2023-09-22 19:49:09 +00:00
// EnvControllerHeartbeatTime will update the heartbeat for application controller to claim shard
EnvControllerHeartbeatTime = "ARGOCD_CONTROLLER_HEARTBEAT_TIME"
2020-10-09 20:16:54 +00:00
// EnvControllerShard is the shard number that should be handled by controller
EnvControllerShard = "ARGOCD_CONTROLLER_SHARD"
2023-06-05 13:19:14 +00:00
// EnvControllerShardingAlgorithm is the distribution sharding algorithm to be used: legacy or round-robin
EnvControllerShardingAlgorithm = "ARGOCD_CONTROLLER_SHARDING_ALGORITHM"
2024-06-11 15:41:55 +00:00
// EnvEnableDynamicClusterDistribution enables dynamic sharding (ALPHA)
2023-09-30 00:41:36 +00:00
EnvEnableDynamicClusterDistribution = "ARGOCD_ENABLE_DYNAMIC_CLUSTER_DISTRIBUTION"
2020-11-24 00:44:09 +00:00
// EnvEnableGRPCTimeHistogramEnv enables gRPC metrics collection
EnvEnableGRPCTimeHistogramEnv = "ARGOCD_ENABLE_GRPC_TIME_HISTOGRAM"
2021-02-19 22:24:32 +00:00
// EnvGithubAppCredsExpirationDuration controls the caching of Github app credentials. This value is in minutes (default: 60)
EnvGithubAppCredsExpirationDuration = "ARGOCD_GITHUB_APP_CREDS_EXPIRATION_DURATION"
2026-04-16 15:16:47 +00:00
// EnvAzureServicePrincipalCredsExpirationDuration controls the caching of Azure service principal credentials. This value is in minutes (default: 59). Any value greater than 59 will be set to 59 minutes
EnvAzureServicePrincipalCredsExpirationDuration = "ARGOCD_AZURE_SERVICE_PRINCIPAL_CREDS_EXPIRATION_DURATION"
2021-03-03 22:07:59 +00:00
// EnvHelmIndexCacheDuration controls how the helm repository index file is cached for (default: 0)
EnvHelmIndexCacheDuration = "ARGOCD_HELM_INDEX_CACHE_DURATION"
2023-03-29 19:41:22 +00:00
// EnvAppConfigPath allows to override the configuration path for repo server
2021-03-16 16:23:10 +00:00
EnvAppConfigPath = "ARGOCD_APP_CONF_PATH"
2024-09-17 09:34:25 +00:00
// EnvAuthToken is the environment variable name for the auth token used by the CLI
EnvAuthToken = "ARGOCD_AUTH_TOKEN"
2021-05-28 23:27:57 +00:00
// EnvLogFormat log format that is defined by `--logformat` option
EnvLogFormat = "ARGOCD_LOG_FORMAT"
// EnvLogLevel log level that is defined by `--loglevel` option
EnvLogLevel = "ARGOCD_LOG_LEVEL"
2024-03-13 20:19:26 +00:00
// EnvLogFormatEnableFullTimestamp enables the FullTimestamp option in logs
EnvLogFormatEnableFullTimestamp = "ARGOCD_LOG_FORMAT_ENABLE_FULL_TIMESTAMP"
2025-01-14 16:10:14 +00:00
// EnvLogFormatTimestamp is the timestamp format used in logs
EnvLogFormatTimestamp = "ARGOCD_LOG_FORMAT_TIMESTAMP"
2021-10-21 21:37:39 +00:00
// EnvMaxCookieNumber max number of chunks a cookie can be broken into
EnvMaxCookieNumber = "ARGOCD_MAX_COOKIE_NUMBER"
2021-11-08 17:47:10 +00:00
// EnvPluginSockFilePath allows to override the pluginSockFilePath for repo server and cmp server
EnvPluginSockFilePath = "ARGOCD_PLUGINSOCKFILEPATH"
2022-03-15 19:06:21 +00:00
// EnvCMPChunkSize defines the chunk size in bytes used when sending files to the cmp server
EnvCMPChunkSize = "ARGOCD_CMP_CHUNK_SIZE"
// EnvCMPWorkDir defines the full path of the work directory used by the CMP server
EnvCMPWorkDir = "ARGOCD_CMP_WORKDIR"
2023-06-21 01:32:14 +00:00
// EnvGPGDataPath overrides the location where GPG keyring for signature verification is stored
EnvGPGDataPath = "ARGOCD_GPG_DATA_PATH"
2025-02-22 06:50:15 +00:00
// EnvServer is the server address of the Argo CD API server.
EnvServer = "ARGOCD_SERVER"
2023-08-22 19:29:13 +00:00
// EnvServerName is the name of the Argo CD server component, as specified by the value under the LabelKeyAppName label key.
EnvServerName = "ARGOCD_SERVER_NAME"
// EnvRepoServerName is the name of the Argo CD repo server component, as specified by the value under the LabelKeyAppName label key.
EnvRepoServerName = "ARGOCD_REPO_SERVER_NAME"
// EnvAppControllerName is the name of the Argo CD application controller component, as specified by the value under the LabelKeyAppName label key.
EnvAppControllerName = "ARGOCD_APPLICATION_CONTROLLER_NAME"
// EnvRedisName is the name of the Argo CD redis component, as specified by the value under the LabelKeyAppName label key.
EnvRedisName = "ARGOCD_REDIS_NAME"
// EnvRedisHaProxyName is the name of the Argo CD Redis HA proxy component, as specified by the value under the LabelKeyAppName label key.
EnvRedisHaProxyName = "ARGOCD_REDIS_HAPROXY_NAME"
2023-10-18 20:57:21 +00:00
// EnvGRPCKeepAliveMin defines the GRPCKeepAliveEnforcementMinimum, used in the grpc.KeepaliveEnforcementPolicy. Expects a "Duration" format (e.g. 10s).
EnvGRPCKeepAliveMin = "ARGOCD_GRPC_KEEP_ALIVE_MIN"
2023-12-18 20:37:13 +00:00
// EnvServerSideDiff defines the env var used to enable ServerSide Diff feature.
// If defined, value must be "true" or "false".
EnvServerSideDiff = "ARGOCD_APPLICATION_CONTROLLER_SERVER_SIDE_DIFF"
2024-04-06 01:19:05 +00:00
// EnvGRPCMaxSizeMB is the environment variable to look for a max GRPC message size
EnvGRPCMaxSizeMB = "ARGOCD_GRPC_MAX_SIZE_MB"
2022-03-15 19:06:21 +00:00
)
// Config Management Plugin related constants
const (
// DefaultCMPChunkSize defines chunk size in bytes used when sending files to the cmp server
DefaultCMPChunkSize = 1024
// DefaultCMPWorkDirName defines the work directory name used by the cmp-server
DefaultCMPWorkDirName = "_cmp_server"
2022-08-17 15:48:27 +00:00
2023-02-06 19:49:48 +00:00
ConfigMapPluginDeprecationWarning = "argocd-cm plugins are deprecated, and support will be removed in v2.7. Upgrade your plugin to be installed via sidecar. https://argo-cd.readthedocs.io/en/stable/user-guide/config-management-plugins/"
2018-02-27 11:08:19 +00:00
)
2019-02-13 23:20:40 +00:00
const (
// MinClientVersion is the minimum client version that can interface with this API server.
// When introducing breaking changes to the API or datastructures, this number should be bumped.
// The value here may be lower than the current value in VERSION
2020-04-15 21:17:24 +00:00
MinClientVersion = "1.4.0"
2019-02-13 23:20:40 +00:00
// CacheVersion is a objects version cached using util/cache/cache.go.
// Number should be bumped in case of backward incompatible change to make sure cache is invalidated after upgrade.
2020-12-03 18:24:47 +00:00
CacheVersion = "1.8.3"
2019-02-13 23:20:40 +00:00
)
2020-03-18 10:28:31 +00:00
2022-06-08 15:23:41 +00:00
// Constants used by util/clusterauth package
const (
ClusterAuthRequestTimeout = 10 * time . Second
2024-09-30 23:37:51 +00:00
)
const (
BearerTokenTimeout = 30 * time . Second
2022-06-08 15:23:41 +00:00
)
2026-03-10 13:03:48 +00:00
// TokenRevocationTimeout is the maximum time allowed for a server-side token revocation call during logout.
const TokenRevocationTimeout = 10 * time . Second
// TokenRevocationClientTimeout is the maximum time the CLI waits for the server to complete token revocation.
const TokenRevocationClientTimeout = 15 * time . Second
2021-10-08 21:00:09 +00:00
const (
DefaultGitRetryMaxDuration time . Duration = time . Second * 5 // 5s
DefaultGitRetryDuration time . Duration = time . Millisecond * 250 // 0.25s
DefaultGitRetryFactor = int64 ( 2 )
)
2023-08-22 19:29:13 +00:00
// Constants represent the pod selector labels of the Argo CD component names. These values are determined by the
// installation manifests.
const (
DefaultServerName = "argocd-server"
DefaultRepoServerName = "argocd-repo-server"
DefaultApplicationControllerName = "argocd-application-controller"
DefaultRedisName = "argocd-redis"
DefaultRedisHaProxyName = "argocd-redis-ha-haproxy"
)
2020-06-22 16:21:53 +00:00
// GetGnuPGHomePath retrieves the path to use for GnuPG home directory, which is either taken from GNUPGHOME environment or a default value
func GetGnuPGHomePath ( ) string {
2025-01-07 15:25:22 +00:00
gnuPgHome := os . Getenv ( EnvGnuPGHome )
if gnuPgHome == "" {
2020-06-22 16:21:53 +00:00
return DefaultGnuPgHomePath
}
2025-01-07 15:25:22 +00:00
return gnuPgHome
2020-06-22 16:21:53 +00:00
}
2021-11-08 17:47:10 +00:00
// GetPluginSockFilePath retrieves the path of plugin sock file, which is either taken from PluginSockFilePath environment or a default value
func GetPluginSockFilePath ( ) string {
2025-01-07 15:25:22 +00:00
pluginSockFilePath := os . Getenv ( EnvPluginSockFilePath )
if pluginSockFilePath == "" {
2021-11-08 17:47:10 +00:00
return DefaultPluginSockFilePath
}
2025-01-07 15:25:22 +00:00
return pluginSockFilePath
2021-11-08 17:47:10 +00:00
}
2022-03-15 19:06:21 +00:00
// GetCMPChunkSize will return the env var EnvCMPChunkSize value if defined or DefaultCMPChunkSize otherwise.
// If EnvCMPChunkSize is defined but not a valid int, DefaultCMPChunkSize will be returned
func GetCMPChunkSize ( ) int {
if chunkSizeStr := os . Getenv ( EnvCMPChunkSize ) ; chunkSizeStr != "" {
chunkSize , err := strconv . Atoi ( chunkSizeStr )
if err != nil {
logrus . Warnf ( "invalid env var value for %s: not a valid int: %s. Default value will be used." , EnvCMPChunkSize , err )
return DefaultCMPChunkSize
}
return chunkSize
}
return DefaultCMPChunkSize
}
// GetCMPWorkDir will return the full path of the work directory used by the CMP server.
2024-05-28 09:51:04 +00:00
// This directory and all it's contents will be deleted during CMP bootstrap.
2022-03-15 19:06:21 +00:00
func GetCMPWorkDir ( ) string {
if workDir := os . Getenv ( EnvCMPWorkDir ) ; workDir != "" {
return filepath . Join ( workDir , DefaultCMPWorkDirName )
}
return filepath . Join ( os . TempDir ( ) , DefaultCMPWorkDirName )
}
2022-03-29 22:11:02 +00:00
const (
2023-03-29 19:41:22 +00:00
// AnnotationApplicationSetRefresh is an annotation that is added when an ApplicationSet is requested to be refreshed by a webhook. The ApplicationSet controller will remove this annotation at the end of reconciliation.
2022-03-29 22:11:02 +00:00
AnnotationApplicationSetRefresh = "argocd.argoproj.io/application-set-refresh"
)
2022-07-11 16:02:10 +00:00
// gRPC settings
const (
2023-10-18 20:57:21 +00:00
defaultGRPCKeepAliveEnforcementMinimum = 10 * time . Second
2022-07-11 16:02:10 +00:00
)
2022-08-17 13:32:47 +00:00
2023-10-18 20:57:21 +00:00
func GetGRPCKeepAliveEnforcementMinimum ( ) time . Duration {
if GRPCKeepAliveMinStr := os . Getenv ( EnvGRPCKeepAliveMin ) ; GRPCKeepAliveMinStr != "" {
GRPCKeepAliveMin , err := time . ParseDuration ( GRPCKeepAliveMinStr )
if err != nil {
logrus . Warnf ( "invalid env var value for %s: cannot parse: %s. Default value %s will be used." , EnvGRPCKeepAliveMin , err , defaultGRPCKeepAliveEnforcementMinimum )
return defaultGRPCKeepAliveEnforcementMinimum
}
return GRPCKeepAliveMin
}
return defaultGRPCKeepAliveEnforcementMinimum
}
func GetGRPCKeepAliveTime ( ) time . Duration {
// GRPCKeepAliveTime is 2x enforcement minimum to ensure network jitter does not introduce ENHANCE_YOUR_CALM errors
return 2 * GetGRPCKeepAliveEnforcementMinimum ( )
}
2022-08-17 13:32:47 +00:00
// Security severity logging
const (
2023-06-15 21:17:04 +00:00
SecurityField = "security"
// SecurityCWEField is the logs field for the CWE associated with a log line. CWE stands for Common Weakness Enumeration. See https://cwe.mitre.org/
SecurityCWEField = "CWE"
SecurityCWEIncompleteCleanup = 459
SecurityCWEMissingReleaseOfFileDescriptor = 775
SecurityEmergency = 5 // Indicates unmistakably malicious events that should NEVER occur accidentally and indicates an active attack (i.e. brute forcing, DoS)
SecurityCritical = 4 // Indicates any malicious or exploitable event that had a side effect (i.e. secrets being left behind on the filesystem)
SecurityHigh = 3 // Indicates likely malicious events but one that had no side effects or was blocked (i.e. out of bounds symlinks in repos)
SecurityMedium = 2 // Could indicate malicious events, but has a high likelihood of being user/system error (i.e. access denied)
SecurityLow = 1 // Unexceptional entries (i.e. successful access logs)
2022-08-17 13:32:47 +00:00
)
2023-01-25 14:15:03 +00:00
2023-03-29 19:41:22 +00:00
// TokenVerificationError is a generic error message for a failure to verify a JWT
2023-01-25 14:15:03 +00:00
const TokenVerificationError = "failed to verify the token"
2025-03-27 16:37:52 +00:00
var ErrTokenVerification = errors . New ( TokenVerificationError )
2023-02-16 14:07:57 +00:00
var PermissionDeniedAPIError = status . Error ( codes . PermissionDenied , "permission denied" )
2024-07-15 19:09:49 +00:00
2026-02-26 15:07:00 +00:00
var WatchAPIBufferSize = env . ParseNumFromEnv ( EnvWatchAPIBufferSize , 1000 , 0 , math . MaxInt32 )
2024-07-15 19:09:49 +00:00
// Redis password consts
const (
2024-09-30 23:37:51 +00:00
// RedisInitialCredentials is the name for the argocd kubernetes secret which will have the redis password
RedisInitialCredentials = "argocd-redis"
// RedisInitialCredentialsKey is the key for the argocd kubernetes secret that maps to the redis password
RedisInitialCredentialsKey = "auth"
2024-07-15 19:09:49 +00:00
)
/ *
SetOptionalRedisPasswordFromKubeConfig sets the optional Redis password if it exists in the k8s namespace ' s secrets .
We specify kubeClient as kubernetes . Interface to allow for mocking in tests , but this should be treated as a kubernetes . Clientset param .
* /
func SetOptionalRedisPasswordFromKubeConfig ( ctx context . Context , kubeClient kubernetes . Interface , namespace string , redisOptions * redis . Options ) error {
2024-12-31 08:34:11 +00:00
secret , err := kubeClient . CoreV1 ( ) . Secrets ( namespace ) . Get ( ctx , RedisInitialCredentials , metav1 . GetOptions { } )
2024-07-15 19:09:49 +00:00
if err != nil {
2024-09-30 23:37:51 +00:00
return fmt . Errorf ( "failed to get secret %s/%s: %w" , namespace , RedisInitialCredentials , err )
2024-07-15 19:09:49 +00:00
}
if secret == nil {
2024-09-30 23:37:51 +00:00
return fmt . Errorf ( "failed to get secret %s/%s: secret is nil" , namespace , RedisInitialCredentials )
2024-07-15 19:09:49 +00:00
}
2024-09-30 23:37:51 +00:00
_ , ok := secret . Data [ RedisInitialCredentialsKey ]
2024-07-15 19:09:49 +00:00
if ! ok {
2024-09-30 23:37:51 +00:00
return fmt . Errorf ( "secret %s/%s does not contain key %s" , namespace , RedisInitialCredentials , RedisInitialCredentialsKey )
2024-07-15 19:09:49 +00:00
}
2024-09-30 23:37:51 +00:00
redisOptions . Password = string ( secret . Data [ RedisInitialCredentialsKey ] )
2024-07-15 19:09:49 +00:00
return nil
}