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 web-based terminal #1309

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
9 changes: 9 additions & 0 deletions api/v1beta1/argocd_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,9 @@ type ArgoCDSpec struct {
//+operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Version",xDescriptors={"urn:alm:descriptor:com.tectonic.ui:fieldGroup:ArgoCD","urn:alm:descriptor:com.tectonic.ui:text"}
Version string `json:"version,omitempty"`

// WebTerminal defines the web terminal options for ArgoCD.
WebTerminal ArgoCDWebTerminalSpec `json:"webTerminal,omitempty"`

// Banner defines an additional banner to be displayed in Argo CD UI
Banner *Banner `json:"banner,omitempty"`
}
Expand Down Expand Up @@ -957,6 +960,12 @@ type ArgoCDTLSSpec struct {
InitialCerts map[string]string `json:"initialCerts,omitempty"`
}

// ArgoCDWebTerminalSpec defines the web terminal options for ArgoCD.
type ArgoCDWebTerminalSpec struct {
// Enabled defines whether the web terminal is enabled
Enabled bool `json:"enabled"`
}

type SSHHostsSpec struct {
// ExcludeDefaultHosts describes whether you would like to include the default
// list of SSH Known Hosts provided by ArgoCD.
Expand Down
16 changes: 16 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions common/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ const (
// ArgoCDDefaultKustomizeBuildOptions is the default kustomize build options.
ArgoCDDefaultKustomizeBuildOptions = ""

// ArgoCDDefaultWebTerminalEnabled is the default web terminal enabled switch.
ArgoCDDefaultWebTerminalEnabled = "false"

// ArgoCDKeycloakImage is the default Keycloak Image used for the non-openshift platforms when not specified.
ArgoCDKeycloakImage = "quay.io/keycloak/keycloak"

Expand Down
3 changes: 3 additions & 0 deletions common/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ const (
// ArgoCDKeyUsersAnonymousEnabled is the configuration key for anonymous user access.
ArgoCDKeyUsersAnonymousEnabled = "users.anonymous.enabled"

// ArgoCDKeyWebTerminalEnabled is the configuration key for enabling the web terminal.
ArgoCDKeyWebTerminalEnabled = "exec.enabled"

// ArgoCDDexImageEnvName is the environment variable used to get the image
// to used for the Dex container.
ArgoCDDexImageEnvName = "ARGOCD_DEX_IMAGE"
Expand Down
9 changes: 9 additions & 0 deletions config/crd/bases/argoproj.io_argocds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13798,6 +13798,15 @@ spec:
description: Version is the tag to use with the ArgoCD container image
for all ArgoCD components.
type: string
webTerminal:
description: WebTerminal defines the web terminal options for ArgoCD.
properties:
enabled:
description: Enabled defines whether the web terminal is enabled
type: boolean
required:
- enabled
type: object
type: object
status:
description: ArgoCDStatus defines the observed state of ArgoCD
Expand Down
10 changes: 10 additions & 0 deletions controllers/argocd/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,15 @@ func getKustomizeBuildOptions(cr *argoproj.ArgoCD) string {
return kbo
}

// getWebTerminalEnabled will return whether the web terminal is enabled for the given ArgoCD.
func getWebTerminalEnabled(cr *argoproj.ArgoCD) string {
wte := common.ArgoCDDefaultWebTerminalEnabled
if cr.Spec.WebTerminal.Enabled {
wte = "true"
}
return wte
}

// getOIDCConfig will return the OIDC configuration for the given ArgoCD.
func getOIDCConfig(cr *argoproj.ArgoCD) string {
config := common.ArgoCDDefaultOIDCConfig
Expand Down Expand Up @@ -377,6 +386,7 @@ func (r *ReconcileArgoCD) reconcileArgoConfigMap(cr *argoproj.ArgoCD) error {
cm.Data[common.ArgoCDKeyHelpChatURL] = getHelpChatURL(cr)
cm.Data[common.ArgoCDKeyHelpChatText] = getHelpChatText(cr)
cm.Data[common.ArgoCDKeyKustomizeBuildOptions] = getKustomizeBuildOptions(cr)
cm.Data[common.ArgoCDKeyWebTerminalEnabled] = getWebTerminalEnabled(cr)

if len(cr.Spec.KustomizeVersions) > 0 {
for _, kv := range cr.Spec.KustomizeVersions {
Expand Down
1 change: 1 addition & 0 deletions controllers/argocd/configmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ func TestReconcileArgoCD_reconcileArgoConfigMap(t *testing.T) {
"statusbadge.enabled": "false",
"url": "https://argocd-server",
"users.anonymous.enabled": "false",
"exec.enabled": "false",
}

cmdTests := []struct {
Expand Down
25 changes: 21 additions & 4 deletions controllers/argocd/policyrule.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"golang.org/x/mod/semver"

argoproj "github.com/argoproj-labs/argocd-operator/api/v1beta1"
"github.com/argoproj-labs/argocd-operator/common"

v1 "k8s.io/api/rbac/v1"
Expand Down Expand Up @@ -81,8 +82,8 @@ func policyRuleForDexServer() []v1.PolicyRule {
}
}

func policyRuleForServer() []v1.PolicyRule {
return []v1.PolicyRule{
func policyRuleForServer(cr *argoproj.ArgoCD) []v1.PolicyRule {
rules := []v1.PolicyRule{
{
APIGroups: []string{
"*",
Expand Down Expand Up @@ -159,6 +160,22 @@ func policyRuleForServer() []v1.PolicyRule {
},
},
}

if cr.Spec.WebTerminal.Enabled {
rules = append(rules, v1.PolicyRule{
APIGroups: []string{
"",
},
Resources: []string{
"pods/exec",
},
Verbs: []string{
"create",
},
})
}

return rules
}

func policyRuleForNotificationsController() []v1.PolicyRule {
Expand Down Expand Up @@ -316,7 +333,7 @@ func policyRuleForServerClusterRole() []v1.PolicyRule {
}
}

func getPolicyRuleList(client client.Client) []struct {
func getPolicyRuleList(client client.Client, cr *argoproj.ArgoCD) []struct {
name string
policyRule []v1.PolicyRule
} {
Expand All @@ -332,7 +349,7 @@ func getPolicyRuleList(client client.Client) []struct {
policyRule: policyRuleForDexServer(),
}, {
name: common.ArgoCDServerComponent,
policyRule: policyRuleForServer(),
policyRule: policyRuleForServer(cr),
}, {
name: common.ArgoCDRedisHAComponent,
policyRule: policyRuleForRedisHa(client),
Expand Down
2 changes: 1 addition & 1 deletion controllers/argocd/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func newClusterRole(name string, rules []v1.PolicyRule, cr *argoproj.ArgoCD) *v1

// reconcileRoles will ensure that all ArgoCD Service Accounts are configured.
func (r *ReconcileArgoCD) reconcileRoles(cr *argoproj.ArgoCD) error {
params := getPolicyRuleList(r.Client)
params := getPolicyRuleList(r.Client, cr)

for _, param := range params {
if _, err := r.reconcileRole(param.name, param.policyRule, cr); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion controllers/argocd/rolebinding.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func newRoleBindingWithname(name string, cr *argoproj.ArgoCD) *v1.RoleBinding {

// reconcileRoleBindings will ensure that all ArgoCD RoleBindings are configured.
func (r *ReconcileArgoCD) reconcileRoleBindings(cr *argoproj.ArgoCD) error {
params := getPolicyRuleList(r.Client)
params := getPolicyRuleList(r.Client, cr)

for _, param := range params {
if err := r.reconcileRoleBinding(param.name, param.policyRule, cr); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion controllers/argocd/service_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func getServiceAccountName(crName, name string) string {

// reconcileServiceAccounts will ensure that all ArgoCD Service Accounts are configured.
func (r *ReconcileArgoCD) reconcileServiceAccounts(cr *argoproj.ArgoCD) error {
params := getPolicyRuleList(r.Client)
params := getPolicyRuleList(r.Client, cr)

for _, param := range params {
if err := r.reconcileServiceAccountPermissions(param.name, param.policyRule, cr); err != nil {
Expand Down
Loading