Skip to content

Commit b063a51

Browse files
committed
feat: add HelperConfig field to SpiffeConfig schema
Add HelperConfig string field to SpiffeConfig struct so PlatformConfig can carry raw spiffe-helper helper.conf content. Wire default content into CompiledDefaults() and log truncated snippet on startup. RHAIENG-4939 Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com> Signed-off-by: Ian Miller <milleryan2003@gmail.com>
1 parent 2e9f614 commit b063a51

4 files changed

Lines changed: 76 additions & 5 deletions

File tree

kagenti-operator/internal/webhook/config/defaults.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,21 @@ import (
55
"k8s.io/apimachinery/pkg/api/resource"
66
)
77

8+
// DefaultSpiffeHelperConfig is the default helper.conf content for spiffe-helper.
9+
// Keep in sync with charts/kagenti-operator/values.yaml defaults.spiffe.helperConfig.
10+
const DefaultSpiffeHelperConfig = `agent_address = "/spiffe-workload-api/spire-agent.sock"
11+
cmd = ""
12+
cmd_args = ""
13+
svid_file_name = "/opt/svid.pem"
14+
svid_key_file_name = "/opt/svid_key.pem"
15+
svid_bundle_file_name = "/opt/svid_bundle.pem"
16+
cert_file_mode = 0644
17+
key_file_mode = 0640
18+
jwt_svids = [{jwt_audience="http://keycloak.localtest.me:8080/realms/kagenti", jwt_svid_file_name="/opt/jwt_svid.token"}]
19+
jwt_svid_file_mode = 0644
20+
include_federated_domains = true
21+
`
22+
823
// CompiledDefaults returns hardcoded defaults used when no config is provided
924
func CompiledDefaults() *PlatformConfig {
1025
return &PlatformConfig{
@@ -79,8 +94,9 @@ func CompiledDefaults() *PlatformConfig {
7994
DefaultScopes: []string{"openid"},
8095
},
8196
Spiffe: SpiffeConfig{
82-
TrustDomain: "cluster.local",
83-
SocketPath: "unix:///spiffe-workload-api/spire-agent.sock",
97+
TrustDomain: "cluster.local",
98+
SocketPath: "unix:///spiffe-workload-api/spire-agent.sock",
99+
HelperConfig: DefaultSpiffeHelperConfig,
84100
},
85101
Observability: ObservabilityConfig{
86102
LogLevel: "info",

kagenti-operator/internal/webhook/config/loader.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,14 @@ func logConfig(cfg *PlatformConfig, source string) {
227227
"defaultAudience", cfg.TokenExchange.DefaultAudience,
228228
"defaultScopes", cfg.TokenExchange.DefaultScopes,
229229
)
230+
helperSnippet := cfg.Spiffe.HelperConfig
231+
if len(helperSnippet) > 80 {
232+
helperSnippet = helperSnippet[:80] + "..."
233+
}
230234
log.Info("[config] spiffe",
231235
"trustDomain", cfg.Spiffe.TrustDomain,
232236
"socketPath", cfg.Spiffe.SocketPath,
237+
"helperConfig", helperSnippet,
233238
)
234239
log.Info("=============================================")
235240
}

kagenti-operator/internal/webhook/config/types.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,9 @@ type TokenExchangeDefaults struct {
8686
}
8787

8888
type SpiffeConfig struct {
89-
TrustDomain string `json:"trustDomain" yaml:"trustDomain"`
90-
SocketPath string `json:"socketPath" yaml:"socketPath"`
89+
TrustDomain string `json:"trustDomain" yaml:"trustDomain"`
90+
SocketPath string `json:"socketPath" yaml:"socketPath"`
91+
HelperConfig string `json:"helperConfig" yaml:"helperConfig"`
9192
}
9293

9394
type ObservabilityConfig struct {

kagenti-operator/internal/webhook/config/types_test.go

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
package config
22

3-
import "testing"
3+
import (
4+
"strings"
5+
"testing"
6+
7+
"sigs.k8s.io/yaml"
8+
)
49

510
// TransparentPort is the REDIRECT target for the enforce-redirect guard; it must
611
// be a valid, non-privileged port (the proxy binds it as a non-root user).
@@ -60,3 +65,47 @@ func TestValidate_IptablesCmd(t *testing.T) {
6065
})
6166
}
6267
}
68+
69+
func TestCompiledDefaults_SpiffeHelperConfig(t *testing.T) {
70+
cfg := CompiledDefaults()
71+
if cfg.Spiffe.HelperConfig == "" {
72+
t.Fatal("CompiledDefaults().Spiffe.HelperConfig must not be empty")
73+
}
74+
if !strings.Contains(cfg.Spiffe.HelperConfig, "agent_address") {
75+
t.Error("HelperConfig must contain agent_address")
76+
}
77+
if !strings.Contains(cfg.Spiffe.HelperConfig, "svid_file_name") {
78+
t.Error("HelperConfig must contain svid_file_name")
79+
}
80+
}
81+
82+
func TestSpiffeHelperConfig_YAMLRoundTrip(t *testing.T) {
83+
input := `
84+
spiffe:
85+
trustDomain: example.org
86+
socketPath: "unix:///custom/socket.sock"
87+
helperConfig: |
88+
agent_address = "/custom/socket.sock"
89+
cmd = ""
90+
`
91+
var cfg PlatformConfig
92+
if err := yaml.Unmarshal([]byte(input), &cfg); err != nil {
93+
t.Fatalf("YAML unmarshal failed: %v", err)
94+
}
95+
if cfg.Spiffe.TrustDomain != "example.org" {
96+
t.Errorf("TrustDomain = %q, want example.org", cfg.Spiffe.TrustDomain)
97+
}
98+
if !strings.Contains(cfg.Spiffe.HelperConfig, "agent_address") {
99+
t.Error("HelperConfig not loaded from YAML")
100+
}
101+
}
102+
103+
func TestDeepCopy_PreservesHelperConfig(t *testing.T) {
104+
cfg := CompiledDefaults()
105+
cfg.Spiffe.HelperConfig = "custom_helper_config"
106+
107+
copied := cfg.DeepCopy()
108+
if copied.Spiffe.HelperConfig != "custom_helper_config" {
109+
t.Errorf("DeepCopy lost HelperConfig: got %q", copied.Spiffe.HelperConfig)
110+
}
111+
}

0 commit comments

Comments
 (0)