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

Use same SELinux config option for both server and agent nodes #377

Merged
merged 3 commits into from
Apr 11, 2024
Merged
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
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* [#359](https://github.com/suse-edge/edge-image-builder/issues/359) - Helm validation does not check if a chart uses an undefined repository
* [#362](https://github.com/suse-edge/edge-image-builder/issues/362) - Helm templating failure
* [#365](https://github.com/suse-edge/edge-image-builder/issues/365) - Unable to locate downloaded Helm charts
* [#374](https://github.com/suse-edge/edge-image-builder/issues/374) - Enable SELinux support for Kubernetes agents if servers enforce it

---

Expand Down
11 changes: 11 additions & 0 deletions pkg/kubernetes/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const (
tlsSANKey = "tls-san"
disableKey = "disable"
clusterInitKey = "cluster-init"
selinuxKey = "selinux"
)

type Cluster struct {
Expand Down Expand Up @@ -64,6 +65,7 @@ func NewCluster(kubernetes *image.Kubernetes, configPath string) (*Cluster, erro
// Ensure the agent uses the same cluster configuration values as the server
agentConfig[tokenKey] = serverConfig[tokenKey]
agentConfig[serverKey] = serverConfig[serverKey]
agentConfig[selinuxKey] = serverConfig[selinuxKey]
if strings.Contains(kubernetes.Version, image.KubernetesDistroRKE2) {
agentConfig[cniKey] = serverConfig[cniKey]
}
Expand Down Expand Up @@ -164,6 +166,7 @@ func setMultiNodeConfigDefaults(kubernetes *image.Kubernetes, config map[string]

setClusterToken(config)
appendClusterTLSSAN(config, kubernetes.Network.APIVIP)
setSELinux(config)
if kubernetes.Network.APIHost != "" {
appendClusterTLSSAN(config, kubernetes.Network.APIHost)
}
Expand Down Expand Up @@ -202,6 +205,14 @@ func setClusterAPIAddress(config map[string]any, apiAddress string, port int) {
config[serverKey] = fmt.Sprintf("https://%s:%d", apiAddress, port)
}

func setSELinux(config map[string]any) {
if _, ok := config[selinuxKey].(bool); ok {
return
}

config[selinuxKey] = false
}

func appendClusterTLSSAN(config map[string]any, address string) {
if address == "" {
zap.S().Warn("Attempted to append TLS SAN with an empty address")
Expand Down
7 changes: 4 additions & 3 deletions pkg/kubernetes/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,20 +113,21 @@ func TestNewCluster_MultiNodeRKE2_MissingConfig(t *testing.T) {
})
assert.Equal(t, "cilium", cluster.InitialiserConfig["cni"])
assert.Equal(t, []string{"192.168.122.50", "api.suse.edge.com"}, cluster.InitialiserConfig["tls-san"])
assert.Equal(t, false, cluster.InitialiserConfig["selinux"])
assert.Nil(t, cluster.InitialiserConfig["server"])
assert.Nil(t, cluster.InitialiserConfig["selinux"])

require.NotNil(t, cluster.ServerConfig)
assert.Equal(t, "cilium", cluster.ServerConfig["cni"])
assert.Equal(t, []string{"192.168.122.50", "api.suse.edge.com"}, cluster.ServerConfig["tls-san"])
assert.Equal(t, clusterToken, cluster.ServerConfig["token"])
assert.Equal(t, "https://192.168.122.50:9345", cluster.ServerConfig["server"])
assert.Nil(t, cluster.ServerConfig["selinux"])
assert.Equal(t, false, cluster.ServerConfig["selinux"])

require.NotNil(t, cluster.AgentConfig)
assert.Equal(t, "cilium", cluster.AgentConfig["cni"])
assert.Equal(t, clusterToken, cluster.AgentConfig["token"])
assert.Equal(t, "https://192.168.122.50:9345", cluster.AgentConfig["server"])
assert.Equal(t, false, cluster.AgentConfig["selinux"])
assert.Nil(t, cluster.AgentConfig["tls-san"])
assert.Nil(t, cluster.AgentConfig["debug"])
}
Expand Down Expand Up @@ -176,8 +177,8 @@ func TestNewCluster_MultiNodeRKE2_ExistingConfig(t *testing.T) {
assert.Equal(t, "totally-not-generated-one", cluster.AgentConfig["token"])
assert.Equal(t, "https://192.168.122.50:9345", cluster.AgentConfig["server"])
assert.Equal(t, true, cluster.AgentConfig["debug"])
assert.Equal(t, true, cluster.AgentConfig["selinux"])
assert.Nil(t, cluster.AgentConfig["tls-san"])
assert.Nil(t, cluster.AgentConfig["selinux"])
}

func TestNewCluster_MultiNode_MissingInitialiser(t *testing.T) {
Expand Down
Loading