Skip to content

Commit a2a7a63

Browse files
authored
fix: Remove username/password from CLI's create agent function (#564)
Signed-off-by: jannfis <[email protected]>
1 parent b07ebdb commit a2a7a63

File tree

4 files changed

+24
-76
lines changed

4 files changed

+24
-76
lines changed

cmd/ctl/agent.go

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package main
1616

1717
import (
18-
"bufio"
1918
"bytes"
2019
"context"
2120
"crypto/tls"
@@ -26,7 +25,6 @@ import (
2625
"os"
2726
"strconv"
2827
"strings"
29-
"syscall"
3028
"text/tabwriter"
3129
"time"
3230

@@ -39,7 +37,6 @@ import (
3937
"github.com/argoproj/argo-cd/v3/pkg/apis/application/v1alpha1"
4038
"github.com/argoproj/argo-cd/v3/util/db"
4139
"github.com/spf13/cobra"
42-
"golang.org/x/term"
4340
"gopkg.in/yaml.v3"
4441
v1 "k8s.io/api/core/v1"
4542
"k8s.io/apimachinery/pkg/api/errors"
@@ -103,10 +100,8 @@ func generateAgentClientCert(agentName string, clt *kube.KubernetesClient) (clie
103100

104101
func NewAgentCreateCommand() *cobra.Command {
105102
var (
106-
rpServer string
107-
rpUsername string
108-
rpPassword string
109-
addLabels []string
103+
rpServer string
104+
addLabels []string
110105
)
111106
command := &cobra.Command{
112107
Short: "Create a new agent configuration",
@@ -150,35 +145,6 @@ func NewAgentCreateCommand() *cobra.Command {
150145
cmdutil.Fatal("Agent %s exists.", agentName)
151146
}
152147

153-
// Get desired credentials from the user
154-
if rpUsername == "" {
155-
var err error
156-
reader := bufio.NewReader(os.Stdin)
157-
fmt.Print("Username: ")
158-
rpUsername, err = reader.ReadString('\n')
159-
if err != nil {
160-
cmdutil.Fatal("%v", err)
161-
}
162-
}
163-
if rpUsername != "" && rpPassword == "" {
164-
fmt.Print("Password: ")
165-
pass1, err := term.ReadPassword(int(syscall.Stdin))
166-
fmt.Println()
167-
if err != nil {
168-
cmdutil.Fatal("%v", err)
169-
}
170-
fmt.Print("Repeat password: ")
171-
pass2, err := term.ReadPassword(int(syscall.Stdin))
172-
fmt.Println()
173-
if err != nil {
174-
cmdutil.Fatal("%v", err)
175-
}
176-
if string(pass1) != string(pass2) {
177-
cmdutil.Fatal("Passwords don't match.")
178-
}
179-
rpPassword = string(pass1)
180-
}
181-
182148
clientCert, clientKey, caData, err := generateAgentClientCert(agentName, clt)
183149
if err != nil {
184150
cmdutil.Fatal("%v", err)
@@ -195,8 +161,6 @@ func NewAgentCreateCommand() *cobra.Command {
195161
KeyData: []byte(clientKey),
196162
CAData: []byte(caData),
197163
},
198-
Username: rpUsername,
199-
Password: rpPassword,
200164
},
201165
}
202166

@@ -219,8 +183,6 @@ func NewAgentCreateCommand() *cobra.Command {
219183
},
220184
}
221185
command.Flags().StringVar(&rpServer, "resource-proxy-server", "argocd-agent-resource-proxy:9090", "Address of principal's resource-proxy")
222-
command.Flags().StringVar(&rpUsername, "resource-proxy-username", "", "The username for the resource-proxy")
223-
command.Flags().StringVar(&rpPassword, "resource-proxy-password", "", "The password for the resource-proxy")
224186
command.Flags().StringSliceVarP(&addLabels, "label", "l", []string{}, "Additional labels for the agent")
225187
return command
226188
}

docs/user-guide/adding-agents.md

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ argocd-agentctl jwt create-key \
6565
--upsert
6666
```
6767

68-
**Important**: Replace `<control-plane-context>`, `<principal-ip-addresses>`, and `<principal-dns-names>` with your actual values.
68+
!!! important
69+
Replace `<control-plane-context>`, `<principal-ip-addresses>`, and `<principal-dns-names>` with your actual values.
6970

7071
## Step 2: Create Agent Configuration
7172

@@ -75,35 +76,20 @@ Create the agent configuration on the principal cluster:
7576
argocd-agentctl agent create <agent-name> \
7677
--principal-context <control-plane-context> \
7778
--principal-namespace argocd \
78-
--resource-proxy-server <principal-ip>:9090 \
79-
--resource-proxy-username <agent-name> \
80-
--resource-proxy-password <secure-password>
79+
--resource-proxy-server <resource-proxy-service-name>:9090
8180
```
8281

83-
### Interactive vs Non-Interactive Mode
82+
The resource proxy service's name is usually `argocd-agent-resource-proxy`.
8483

85-
**Interactive Mode** (recommended for development):
86-
87-
```bash
88-
argocd-agentctl agent create production-cluster
89-
# CLI will prompt for username and password
90-
```
91-
92-
**Non-Interactive Mode** (for automation):
93-
94-
```bash
95-
argocd-agentctl agent create production-cluster \
96-
--resource-proxy-username production-cluster \
97-
--resource-proxy-password "$(openssl rand -base64 32)"
98-
```
84+
!!! important
85+
The value given as `resource-proxy-service-name` must match a SAN entry in your resource proxy's TLS certificate
9986

10087
### What This Command Does
10188

10289
1. **Creates Cluster Secret**: Stores agent configuration as an Argo CD cluster secret
103-
2. **Generates Client Certificate**: Creates mTLS certificate for agent authentication
104-
3. **Configures Resource Proxy**: Sets up credentials for live resource viewing
105-
4. **Validates Agent Name**: Ensures the agent name meets requirements
106-
5. **Prevents Duplicates**: Checks that the agent doesn't already exist
90+
2. **Generates Client Certificate**: Creates mTLS certificate for Argo CD to authenticate to the resource proxy
91+
3. **Validates Agent Name**: Ensures the agent name meets requirements
92+
4. **Prevents Duplicates**: Checks that the agent doesn't already exist
10793

10894
## Step 3: Issue Agent Client Certificate
10995

@@ -118,6 +104,7 @@ argocd-agentctl pki issue agent <agent-name> \
118104
```
119105

120106
This command:
107+
121108
- Generates a client certificate signed by the principal's CA
122109
- Stores the certificate in the agent's cluster as a Kubernetes secret
123110
- Configures the certificate with the agent's name as the subject
@@ -139,6 +126,7 @@ kubectl create namespace <agent-name> --context <control-plane-context>
139126
### Option A: Using Kubernetes Manifests
140127

141128
1. **Create Authentication Secret**:
129+
142130
```bash
143131
kubectl create secret generic argocd-agent-agent-userpass \
144132
--from-literal=credentials="userpass:<agent-name>:<password>" \
@@ -147,13 +135,15 @@ kubectl create secret generic argocd-agent-agent-userpass \
147135
```
148136

149137
2. **Deploy Agent Components**:
138+
150139
```bash
151140
kubectl apply -n argocd \
152141
-k 'https://github.com/argoproj-labs/argocd-agent/install/kubernetes/agent?ref=main' \
153142
--context <workload-cluster-context>
154143
```
155144

156145
3. **Configure Agent Parameters**:
146+
157147
```bash
158148
kubectl patch configmap argocd-agent-params \
159149
--namespace argocd \
@@ -193,7 +183,7 @@ data:
193183
agent.server.port: "8443"
194184

195185
# Authentication method
196-
agent.creds: "userpass:/app/config/creds/userpass.creds"
186+
agent.creds: "mtls:^CN=(.+)$"
197187

198188
# TLS settings
199189
agent.tls.client.insecure: "false"
@@ -206,14 +196,15 @@ data:
206196
207197
### Authentication Methods
208198
209-
**UserPass Authentication** (default):
199+
**mTLS Authentication**:
210200
```yaml
211-
agent.creds: "userpass:/app/config/creds/userpass.creds"
201+
agent.creds: "mtls:^CN=(.+)$" # Regex to extract agent ID from cert subject
212202
```
213203
214-
**mTLS Authentication**:
204+
**UserPass Authentication** (deprecated):
205+
215206
```yaml
216-
agent.creds: "mtls:^CN=(.+)$" # Regex to extract agent ID from cert subject
207+
agent.creds: "userpass:/app/config/creds/userpass.creds"
217208
```
218209
219210
## Step 7: Verification
@@ -309,9 +300,8 @@ for agent in "${AGENTS[@]}"; do
309300

310301
# Create agent configuration
311302
argocd-agentctl agent create "$agent" \
312-
--resource-proxy-username "$agent" \
313-
--resource-proxy-password "$(openssl rand -base64 32)"
314-
303+
--resource-proxy-server <resource-proxy-service-name>:9090
304+
315305
# Issue client certificate
316306
argocd-agentctl pki issue agent "$agent" \
317307
--agent-context "cluster-$agent" \
@@ -336,8 +326,6 @@ argocd-agentctl agent inspect <agent-name>
336326
```bash
337327
argocd-agentctl agent reconfigure <agent-name> \
338328
--resource-proxy-server <new-server-address> \
339-
--resource-proxy-username <new-username> \
340-
--resource-proxy-password <new-password> \
341329
--reissue-client-cert
342330
```
343331

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ require (
2626
golang.org/x/crypto v0.42.0
2727
golang.org/x/net v0.44.0
2828
golang.org/x/sync v0.17.0
29-
golang.org/x/term v0.35.0
3029
golang.stackrox.io/grpc-http1 v0.4.0
3130
google.golang.org/genproto/googleapis/api v0.0.0-20250707201910-8d1bb00bc6a7
3231
google.golang.org/grpc v1.75.1
@@ -171,6 +170,7 @@ require (
171170
go.yaml.in/yaml/v2 v2.4.2 // indirect
172171
golang.org/x/oauth2 v0.30.0 // indirect
173172
golang.org/x/sys v0.36.0 // indirect
173+
golang.org/x/term v0.35.0 // indirect
174174
golang.org/x/text v0.29.0 // indirect
175175
golang.org/x/time v0.12.0 // indirect
176176
google.golang.org/genproto v0.0.0-20240213162025-012b6fc9bca9 // indirect

hack/dev-env/create-agent-config.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ for agent in ${AGENTS}; do
8080
if ! ${AGENTCTL} agent inspect ${agent} >/dev/null 2>&1; then
8181
echo " -> Creating cluster secret for agent configuration"
8282
${AGENTCTL} agent create ${agent} \
83-
--resource-proxy-username ${agent} \
84-
--resource-proxy-password ${agent} \
8583
--resource-proxy-server ${ARGOCD_AGENT_RESOURCE_PROXY}:9090
8684
else
8785
echo " -> Reusing existing cluster secret for agent configuration"

0 commit comments

Comments
 (0)