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

Net 4414 remove anyuid openshift requirement #4152

Merged
merged 39 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
016d343
Remove SCC requirement for anyuid for OpenShift
curtbushko Mar 26, 2024
6fc6a2b
add changelog entry
curtbushko Mar 26, 2024
22f02da
fix linter
curtbushko Mar 26, 2024
6dacaee
Update with review comments
curtbushko Mar 27, 2024
b2c3b50
add some print statements
missylbytes Mar 27, 2024
da0ebc1
remove debug output from api gateway kitchen sink
curtbushko Mar 28, 2024
7f57d81
Reorganize if statement that is hard to understand
missylbytes Jun 25, 2024
0707f39
Updates Api Gateway to use the UID and GID given to it by Openshift
missylbytes Jun 26, 2024
c07c0eb
Reorg creation of security context for the webhook container init, no…
missylbytes Jun 26, 2024
cb7f671
Adds net_bind_service capability from https://github.com/hashicorp/co…
missylbytes Jun 26, 2024
0ae97a0
Reorganizes dataplane sidecar logic in webhook to be a bit more under…
missylbytes Jun 26, 2024
cd4a687
Adds tests for NET_BIND_SERVICE from here: https://github.com/hashico…
missylbytes Jun 26, 2024
e20ff5b
Adds changelog
missylbytes Jun 26, 2024
bfe7be8
Didn't reorg the dataplane sidecar in the webhook correctly
missylbytes Jun 26, 2024
1b74985
Fix dataplane sidecar test for webhook
missylbytes Jun 27, 2024
38387fe
Remove some formatting changes, making PR larger than it needs to be.
missylbytes Jun 27, 2024
16bb1de
Uses the Openshift IDs for gateway init container
missylbytes Jun 28, 2024
79a4b45
We only need to check the namespace annotations for Openshift
missylbytes Jun 28, 2024
22dad5e
Update test for Openshift to include namespace with annotations
missylbytes Jun 28, 2024
4ba20cd
Update test to actually test for UID and Group
missylbytes Jun 28, 2024
c06d654
Use separate user/group IDs for app, init + dataplane containers
nathancoleman Jul 3, 2024
0df7090
Merge branch 'main' into net-4414-remove-anyuid-openshift-requirement
missylbytes Jul 5, 2024
886badd
Will not work, worried power is going to go out.
missylbytes Jul 5, 2024
8df6652
Finishes updating Openshift get userIDs and groupIDs, still need to u…
missylbytes Jul 5, 2024
83abb12
Fix missing call updates for Openshift IDs
missylbytes Jul 5, 2024
7c0aedc
Rename function
missylbytes Jul 5, 2024
189f093
Need name of annotation, not value
missylbytes Jul 5, 2024
ab16a35
Fix bug in iptables config generation
nathancoleman Jul 5, 2024
5d715de
Skip dataplane + init containers when building list of application us…
nathancoleman Jul 5, 2024
fa695f7
Remove unused code + unnecessary function export
nathancoleman Jul 5, 2024
28a40fa
Use correct function for API gateway initi container UID
nathancoleman Jul 8, 2024
dd16651
Update gatekeeper tests for OpenShift
nathancoleman Jul 8, 2024
f087c92
Exclude init + dataplane containers based on image instead of name pr…
nathancoleman Jul 8, 2024
92bcb82
Updates Openshift and tests to test for dashes in ranges, and comma s…
missylbytes Jul 8, 2024
6a99515
Updated some tests
missylbytes Jul 8, 2024
a149661
Updated some tests
missylbytes Jul 8, 2024
d2f1b26
Updated sidecar tests
missylbytes Jul 8, 2024
4cf176a
Updated init container test and redirect traffic test for webhook
missylbytes Jul 8, 2024
636a8dd
Un-bump Go version
missylbytes Jul 9, 2024
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
3 changes: 3 additions & 0 deletions .changelog/3813.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
control-plane: Remove anyuid Security Context Constraints (SCC) requirement in OpenShift.
missylbytes marked this conversation as resolved.
Show resolved Hide resolved
```
58 changes: 25 additions & 33 deletions acceptance/framework/consul/helm_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,6 @@ func (h *HelmCluster) SetupConsulClient(t *testing.T, secure bool, release ...st
require.NoError(r, err)
}
})

}
}

Expand Down Expand Up @@ -678,47 +677,40 @@ func configureNamespace(t *testing.T, client kubernetes.Interface, cfg *config.T
}

// configureSCCs creates RoleBindings that bind the default service account to cluster roles
// allowing access to the anyuid and privileged Security Context Constraints on OpenShift.
// allowing access to the privileged Security Context Constraints on OpenShift.
func configureSCCs(t *testing.T, client kubernetes.Interface, cfg *config.TestConfig, namespace string) {
const anyuidClusterRole = "system:openshift:scc:anyuid"
const privilegedClusterRole = "system:openshift:scc:privileged"
anyuidRoleBinding := "anyuid-test"
privilegedRoleBinding := "privileged-test"

// A role binding to allow default service account in the installation namespace access to the SCCs.
{
for clusterRoleName, roleBindingName := range map[string]string{anyuidClusterRole: anyuidRoleBinding, privilegedClusterRole: privilegedRoleBinding} {
// Check if this cluster role binding already exists.
_, err := client.RbacV1().RoleBindings(namespace).Get(context.Background(), roleBindingName, metav1.GetOptions{})

if errors.IsNotFound(err) {
roleBinding := &rbacv1.RoleBinding{
ObjectMeta: metav1.ObjectMeta{
Name: roleBindingName,
},
Subjects: []rbacv1.Subject{
{
Kind: rbacv1.ServiceAccountKind,
Name: "default",
Namespace: namespace,
},
},
RoleRef: rbacv1.RoleRef{
Kind: "ClusterRole",
Name: clusterRoleName,
},
}

_, err = client.RbacV1().RoleBindings(namespace).Create(context.Background(), roleBinding, metav1.CreateOptions{})
require.NoError(t, err)
} else {
require.NoError(t, err)
}
// Check if this cluster role binding already exists.
_, err := client.RbacV1().RoleBindings(namespace).Get(context.Background(), privilegedRoleBinding, metav1.GetOptions{})

if errors.IsNotFound(err) {
roleBinding := &rbacv1.RoleBinding{
ObjectMeta: metav1.ObjectMeta{
Name: privilegedRoleBinding,
},
Subjects: []rbacv1.Subject{
{
Kind: rbacv1.ServiceAccountKind,
Name: "default",
Namespace: namespace,
},
},
RoleRef: rbacv1.RoleRef{
Kind: "ClusterRole",
Name: privilegedClusterRole,
},
}

_, err = client.RbacV1().RoleBindings(namespace).Create(context.Background(), roleBinding, metav1.CreateOptions{})
require.NoError(t, err)
} else {
require.NoError(t, err)
}

helpers.Cleanup(t, cfg.NoCleanupOnFailure, cfg.NoCleanup, func() {
_ = client.RbacV1().RoleBindings(namespace).Delete(context.Background(), anyuidRoleBinding, metav1.DeleteOptions{})
_ = client.RbacV1().RoleBindings(namespace).Delete(context.Background(), privilegedRoleBinding, metav1.DeleteOptions{})
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ func TestAPIGateway_KitchenSink(t *testing.T) {
checkStatusCondition(r, gateway.Status.Conditions, trueCondition("ConsulAccepted", "Accepted"))
require.Len(r, gateway.Status.Listeners, 2)

// http route checks
err = k8sClient.Get(context.Background(), types.NamespacedName{Name: "http-route", Namespace: "default"}, &httpRoute)
require.NoError(r, err)

require.EqualValues(r, int32(1), gateway.Status.Listeners[0].AttachedRoutes)
checkStatusCondition(r, gateway.Status.Listeners[0].Conditions, trueCondition("Accepted", "Accepted"))
checkStatusCondition(r, gateway.Status.Listeners[0].Conditions, falseCondition("Conflicted", "NoConflicts"))
Expand All @@ -152,10 +156,6 @@ func TestAPIGateway_KitchenSink(t *testing.T) {
// now we know we have an address, set it so we can use it
gatewayAddress = gateway.Status.Addresses[0].Value

// http route checks
err = k8sClient.Get(context.Background(), types.NamespacedName{Name: "http-route", Namespace: "default"}, &httpRoute)
require.NoError(r, err)

// check our finalizers
require.Len(r, httpRoute.Finalizers, 1)
require.EqualValues(r, gatewayFinalizer, httpRoute.Finalizers[0])
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ resources:
- secret.yaml
- serviceaccount.yaml
- psp-rolebinding.yaml
- anyuid-scc-rolebinding.yaml
- privileged-scc-rolebinding.yaml
- privileged-scc-rolebinding.yaml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ resources:
- service.yaml
- serviceaccount.yaml
- psp-rolebinding.yaml
- anyuid-scc-rolebinding.yaml
- privileged-scc-rolebinding.yaml
- privileged-scc-rolebinding.yaml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ resources:
- service.yaml
- serviceaccount.yaml
- psp-rolebinding.yaml
- anyuid-scc-rolebinding.yaml
- privileged-scc-rolebinding.yaml
- privileged-scc-rolebinding.yaml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ resources:
- serviceaccount.yaml
- servicedefaults.yaml
- psp-rolebinding.yaml
- anyuid-scc-rolebinding.yaml
- privileged-scc-rolebinding.yaml
- privileged-scc-rolebinding.yaml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ resources:
- service.yaml
- serviceaccount.yaml
- psp-rolebinding.yaml
- anyuid-scc-rolebinding.yaml
- privileged-scc-rolebinding.yaml
- privileged-scc-rolebinding.yaml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ resources:
- secret.yaml
- serviceaccount.yaml
- psp-rolebinding.yaml
- anyuid-scc-rolebinding.yaml
- privileged-scc-rolebinding.yaml
- privileged-scc-rolebinding.yaml
2 changes: 1 addition & 1 deletion control-plane/api-gateway/gatekeeper/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (g *Gatekeeper) deleteDeployment(ctx context.Context, gwName types.Namespac
}

func (g *Gatekeeper) deployment(gateway gwv1beta1.Gateway, gcc v1alpha1.GatewayClassConfig, config common.HelmConfig, currentReplicas *int32) (*appsv1.Deployment, error) {
initContainer, err := initContainer(config, gateway.Name, gateway.Namespace)
initContainer, err := g.initContainer(config, gateway.Name, gateway.Namespace)
if err != nil {
return nil, err
}
Expand Down
28 changes: 24 additions & 4 deletions control-plane/api-gateway/gatekeeper/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"text/template"

corev1 "k8s.io/api/core/v1"

"k8s.io/utils/pointer"

"github.com/hashicorp/consul-k8s/control-plane/api-gateway/common"
Expand All @@ -35,7 +34,7 @@ type initContainerCommandData struct {

// containerInit returns the init container spec for connect-init that polls for the service and the connect proxy service to be registered
// so that it can save the proxy service id to the shared volume and boostrap Envoy with the proxy-id.
func initContainer(config common.HelmConfig, name, namespace string) (corev1.Container, error) {
func (g Gatekeeper) initContainer(config common.HelmConfig, name, namespace string) (corev1.Container, error) {
data := initContainerCommandData{
AuthMethod: config.AuthMethod,
LogLevel: config.LogLevel,
Expand Down Expand Up @@ -175,9 +174,30 @@ func initContainer(config common.HelmConfig, name, namespace string) (corev1.Con
container.Resources = *config.InitContainerResources
}

// TODO: Melisa we will need this if we match the style of what the webhook does
//ns := &corev1.Namespace{}
// // TODO: contexts
//err := g.Client.Get(context.Background(), client.ObjectKey{
// Name: namespace,
//}, ns)
//if err != nil {
// g.Log.Error(err, "error fetching namespace metadata for deployment")
// return nil, fmt.Errorf("error getting namespace metadata for deployment: %s", err)
//}

uid := pointer.Int64(initContainersUserAndGroupID)
groupID := pointer.Int64(initContainersUserAndGroupID)

// In Openshift we let Openshift set the UID and GID
// TODO: Melisa will probably clean this up to match what webhook does
if config.EnableOpenShift {
uid = nil
groupID = nil
}

container.SecurityContext = &corev1.SecurityContext{
RunAsUser: pointer.Int64(initContainersUserAndGroupID),
RunAsGroup: pointer.Int64(initContainersUserAndGroupID),
RunAsUser: uid,
RunAsGroup: groupID,
RunAsNonRoot: pointer.Bool(true),
Privileged: pointer.Bool(false),
Capabilities: &corev1.Capabilities{
Expand Down
Loading
Loading