Skip to content

Commit 27bcb21

Browse files
Add cluster name and description to CyberArk Discovery and Context snapshot
- Add ClusterName and ClusterDescription fields to Snapshot struct - Populate these fields from Options in PostDataReadingsWithOptions - Add clusterName and clusterDescription Helm values and docs - Populate cluster_id and cluster_description in the rendered configmap - Update values.schema.json to include descriptions for the new values - Add ClusterDescription field to pkg/agent Config and CombinedConfig - Default MachineHub cluster ID from ARK_USERNAME env when not set - Clarify comments and add TODO about ClusterID vs ClusterName naming Signed-off-by: Richard Wall <[email protected]>
1 parent 0ae6dbd commit 27bcb21

File tree

7 files changed

+85
-11
lines changed

7 files changed

+85
-11
lines changed

deploy/charts/disco-agent/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,24 @@ Example: excludeAnnotationKeysRegex: ['^kapp\.k14s\.io/original.*']
277277
> ```yaml
278278
> []
279279
> ```
280+
#### **config.clusterName** ~ `string`
281+
> Default value:
282+
> ```yaml
283+
> ""
284+
> ```
285+
286+
A human readable name for the cluster where the agent is deployed (optional).
287+
288+
This cluster name will be associated with the data that the agent uploads to the Discovery and Context service. If empty (the default), the service account name will be used instead.
289+
#### **config.clusterDescription** ~ `string`
290+
> Default value:
291+
> ```yaml
292+
> ""
293+
> ```
294+
295+
A short description of the cluster where the agent is deployed (optional).
296+
297+
This description will be associated with the data that the agent uploads to the Discovery and Context service. The description should include contact information such as the email address of the cluster administrator, so that any problems and risks identified by the Discovery and Context service can be communicated to the people responsible for the affected secrets.
280298
#### **authentication.secretName** ~ `string`
281299
> Default value:
282300
> ```yaml

deploy/charts/disco-agent/templates/configmap.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ metadata:
77
{{- include "disco-agent.labels" . | nindent 4 }}
88
data:
99
config.yaml: |-
10+
cluster_id: {{ .Values.config.clusterName | quote }}
11+
cluster_description: {{ .Values.config.clusterDescription | quote }}
1012
period: {{ .Values.config.period | quote }}
1113
{{- with .Values.config.excludeAnnotationKeysRegex }}
1214
exclude-annotation-keys-regex:

deploy/charts/disco-agent/values.schema.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@
104104
"helm-values.config": {
105105
"additionalProperties": false,
106106
"properties": {
107+
"clusterDescription": {
108+
"$ref": "#/$defs/helm-values.config.clusterDescription"
109+
},
110+
"clusterName": {
111+
"$ref": "#/$defs/helm-values.config.clusterName"
112+
},
107113
"excludeAnnotationKeysRegex": {
108114
"$ref": "#/$defs/helm-values.config.excludeAnnotationKeysRegex"
109115
},
@@ -116,6 +122,16 @@
116122
},
117123
"type": "object"
118124
},
125+
"helm-values.config.clusterDescription": {
126+
"default": "",
127+
"description": "A short description of the cluster where the agent is deployed (optional).\n\nThis description will be associated with the data that the agent uploads to the Discovery and Context service. The description should include contact information such as the email address of the cluster administrator, so that any problems and risks identified by the Discovery and Context service can be communicated to the people responsible for the affected secrets.",
128+
"type": "string"
129+
},
130+
"helm-values.config.clusterName": {
131+
"default": "",
132+
"description": "A human readable name for the cluster where the agent is deployed (optional).\n\nThis cluster name will be associated with the data that the agent uploads to the Discovery and Context service. If empty (the default), the service account name will be used instead.",
133+
"type": "string"
134+
},
119135
"helm-values.config.excludeAnnotationKeysRegex": {
120136
"default": [],
121137
"description": "You can configure the agent to exclude some annotations or labels from being pushed . All Kubernetes objects are affected. The objects are still pushed, but the specified annotations and labels are removed before being pushed.\n\nDots is the only character that needs to be escaped in the regex. Use either double quotes with escaped single quotes or unquoted strings for the regex to avoid YAML parsing issues with `\\.`.\n\nExample: excludeAnnotationKeysRegex: ['^kapp\\.k14s\\.io/original.*']",

deploy/charts/disco-agent/values.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,22 @@ config:
138138
excludeAnnotationKeysRegex: []
139139
excludeLabelKeysRegex: []
140140

141+
# A human readable name for the cluster where the agent is deployed (optional).
142+
#
143+
# This cluster name will be associated with the data that the agent uploads to
144+
# the Discovery and Context service. If empty (the default), the service
145+
# account name will be used instead.
146+
clusterName: ""
147+
148+
# A short description of the cluster where the agent is deployed (optional).
149+
#
150+
# This description will be associated with the data that the agent uploads to
151+
# the Discovery and Context service. The description should include contact
152+
# information such as the email address of the cluster administrator, so that
153+
# any problems and risks identified by the Discovery and Context service can
154+
# be communicated to the people responsible for the affected secrets.
155+
clusterDescription: ""
156+
141157
authentication:
142158
secretName: agent-credentials
143159

internal/cyberark/dataupload/dataupload.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ type Snapshot struct {
5151
AgentVersion string `json:"agent_version"`
5252
// ClusterID is the unique ID of the Kubernetes cluster which this snapshot was taken from.
5353
ClusterID string `json:"cluster_id"`
54+
// ClusterName is the name of the Kubernetes cluster which this snapshot was taken from.
55+
ClusterName string `json:"cluster_name"`
56+
// ClusterDescription is an optional description of the Kubernetes cluster which this snapshot was taken from.
57+
ClusterDescription string `json:"cluster_description,omitempty"`
5458
// K8SVersion is the version of Kubernetes which the cluster is running.
5559
K8SVersion string `json:"k8s_version"`
5660
// Secrets is a list of Secret resources in the cluster. Not all Secret

pkg/agent/config.go

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,13 @@ type Config struct {
4949
OrganizationID string `yaml:"organization_id"`
5050

5151
// ClusterID is the cluster that the agent is scanning. Used in all modes.
52-
ClusterID string `yaml:"cluster_id"`
52+
//
53+
// TODO(wallrj): ClusterID and ClusterName have become somewhat confusing
54+
// naming-wise. We should consider renaming ClusterID to ClusterName
55+
ClusterID string `yaml:"cluster_id"`
56+
// ClusterDescription is a short description of the cluster. It should
57+
// contain contact details of the cluster administrator, so that any risks
58+
// identified by the backend can be communicated.
5359
ClusterDescription string `yaml:"cluster_description"`
5460
DataGatherers []DataGatherer `yaml:"data-gatherers"`
5561
VenafiCloud *VenafiCloudConfig `yaml:"venafi-cloud,omitempty"`
@@ -340,8 +346,8 @@ const (
340346
MachineHub OutputMode = "MachineHub"
341347
)
342348

343-
// The command-line flags and the config file are combined into this struct by
344-
// ValidateAndCombineConfig.
349+
// The command-line flags and the config file and some environment variables are
350+
// combined into this struct by ValidateAndCombineConfig.
345351
type CombinedConfig struct {
346352
DataGatherers []DataGatherer
347353
Period time.Duration
@@ -352,7 +358,10 @@ type CombinedConfig struct {
352358

353359
OutputMode OutputMode
354360

355-
// Used by all TLSPK modes.
361+
// Used by all modes.
362+
//
363+
// TODO(wallrj): ClusterID and ClusterName have become somewhat confusing
364+
// consider renaming ClusterID to ClusterName.
356365
ClusterID string
357366

358367
// Used by JetstackSecureOAuth, JetstackSecureAPIToken, and
@@ -364,7 +373,11 @@ type CombinedConfig struct {
364373
EndpointPath string // Deprecated.
365374

366375
// VenafiCloudKeypair mode only.
367-
UploadPath string
376+
UploadPath string
377+
378+
// ClusterDescription is a short description of the cluster. It should
379+
// contain contact details of the cluster administrator so that risks identified
380+
// by the backend can be communicated.
368381
ClusterDescription string
369382

370383
// VenafiCloudVenafiConnection mode only.
@@ -557,8 +570,11 @@ func ValidateAndCombineConfig(log logr.Logger, cfg Config, flags AgentCmdFlags)
557570
organizationID = cfg.OrganizationID
558571
clusterID = cfg.ClusterID
559572
case MachineHub:
560-
if cfg.ClusterID != "" {
561-
log.Info(fmt.Sprintf(`Ignoring the cluster_id field in the config file. This field is not needed in %s mode.`, res.OutputMode))
573+
clusterID = cfg.ClusterID
574+
if clusterID == "" {
575+
if arkUsername, found := os.LookupEnv("ARK_USERNAME"); found {
576+
clusterID = arkUsername
577+
}
562578
}
563579
if cfg.OrganizationID != "" {
564580
log.Info(fmt.Sprintf(`Ignoring the organization_id field in the config file. This field is not needed in %s mode.`, res.OutputMode))

pkg/client/client_cyberark.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,20 @@ func NewCyberArk(httpClient *http.Client) (*CyberArkClient, error) {
5252
// It initializes a data upload client with the configured HTTP client and credentials,
5353
// then uploads a snapshot.
5454
// The supplied Options are not used by this publisher.
55-
func (o *CyberArkClient) PostDataReadingsWithOptions(ctx context.Context, readings []*api.DataReading, _ Options) error {
55+
func (o *CyberArkClient) PostDataReadingsWithOptions(ctx context.Context, readings []*api.DataReading, opts Options) error {
5656
log := klog.FromContext(ctx)
57-
var snapshot dataupload.Snapshot
57+
snapshot := dataupload.Snapshot{
58+
ClusterName: opts.ClusterName,
59+
ClusterDescription: opts.ClusterDescription,
60+
AgentVersion: version.PreflightVersion,
61+
}
5862
if err := convertDataReadings(defaultExtractorFunctions, readings, &snapshot); err != nil {
5963
return fmt.Errorf("while converting data readings: %s", err)
6064
}
6165

6266
// Minimize the snapshot to reduce size and improve privacy
6367
minimizeSnapshot(log.V(logs.Debug), &snapshot)
6468

65-
snapshot.AgentVersion = version.PreflightVersion
66-
6769
cfg, err := o.configLoader()
6870
if err != nil {
6971
return err

0 commit comments

Comments
 (0)