Search in sources :

Example 16 with SubjectBuilder

use of io.fabric8.kubernetes.api.model.rbac.SubjectBuilder in project strimzi-kafka-operator by strimzi.

the class ClusterRoleBindingTemplates method clusterRoleBindingsForAllNamespaces.

public static List<ClusterRoleBinding> clusterRoleBindingsForAllNamespaces(String namespace, String coName) {
    LOGGER.info("Creating ClusterRoleBinding that grant cluster-wide access to all OpenShift projects");
    List<ClusterRoleBinding> kCRBList = new ArrayList<>();
    kCRBList.add(new ClusterRoleBindingBuilder().withNewMetadata().withName(coName + "-namespaced").endMetadata().withNewRoleRef().withApiGroup("rbac.authorization.k8s.io").withKind("ClusterRole").withName("strimzi-cluster-operator-namespaced").endRoleRef().withSubjects(new SubjectBuilder().withKind("ServiceAccount").withName("strimzi-cluster-operator").withNamespace(namespace).build()).build());
    kCRBList.add(new ClusterRoleBindingBuilder().withNewMetadata().withName(coName + "-entity-operator").endMetadata().withNewRoleRef().withApiGroup("rbac.authorization.k8s.io").withKind("ClusterRole").withName("strimzi-entity-operator").endRoleRef().withSubjects(new SubjectBuilder().withKind("ServiceAccount").withName("strimzi-cluster-operator").withNamespace(namespace).build()).build());
    return kCRBList;
}
Also used : ClusterRoleBindingBuilder(io.fabric8.kubernetes.api.model.rbac.ClusterRoleBindingBuilder) ClusterRoleBinding(io.fabric8.kubernetes.api.model.rbac.ClusterRoleBinding) ArrayList(java.util.ArrayList) SubjectBuilder(io.fabric8.kubernetes.api.model.rbac.SubjectBuilder)

Example 17 with SubjectBuilder

use of io.fabric8.kubernetes.api.model.rbac.SubjectBuilder in project strimzi-kafka-operator by strimzi.

the class EntityUserOperator method generateRoleBindingForRole.

public RoleBinding generateRoleBindingForRole(String namespace, String watchedNamespace) {
    Subject ks = new SubjectBuilder().withKind("ServiceAccount").withName(EntityOperator.entityOperatorServiceAccountName(cluster)).withNamespace(namespace).build();
    RoleRef roleRef = new RoleRefBuilder().withName(getRoleName()).withApiGroup("rbac.authorization.k8s.io").withKind("Role").build();
    RoleBinding rb = generateRoleBinding(roleBindingForRoleName(cluster), watchedNamespace, roleRef, singletonList(ks));
    // We set OwnerReference only within the same namespace since it does not work cross-namespace
    if (!namespace.equals(watchedNamespace)) {
        rb.getMetadata().setOwnerReferences(Collections.emptyList());
    }
    return rb;
}
Also used : RoleRef(io.fabric8.kubernetes.api.model.rbac.RoleRef) RoleBinding(io.fabric8.kubernetes.api.model.rbac.RoleBinding) SubjectBuilder(io.fabric8.kubernetes.api.model.rbac.SubjectBuilder) Subject(io.fabric8.kubernetes.api.model.rbac.Subject) RoleRefBuilder(io.fabric8.kubernetes.api.model.rbac.RoleRefBuilder)

Example 18 with SubjectBuilder

use of io.fabric8.kubernetes.api.model.rbac.SubjectBuilder in project strimzi by strimzi.

the class RoleBindingOperatorIT method getOriginal.

@Override
protected RoleBinding getOriginal() {
    Subject ks = new SubjectBuilder().withKind("ServiceAccount").withName("my-service-account").withNamespace("my-namespace").build();
    RoleRef roleRef = new RoleRefBuilder().withName("my-cluster-role").withApiGroup("rbac.authorization.k8s.io").withKind("ClusterRole").build();
    return new RoleBindingBuilder().withNewMetadata().withName(resourceName).withNamespace(namespace).withLabels(singletonMap("state", "new")).endMetadata().withSubjects(ks).withRoleRef(roleRef).build();
}
Also used : RoleBindingBuilder(io.fabric8.kubernetes.api.model.rbac.RoleBindingBuilder) RoleRef(io.fabric8.kubernetes.api.model.rbac.RoleRef) SubjectBuilder(io.fabric8.kubernetes.api.model.rbac.SubjectBuilder) Subject(io.fabric8.kubernetes.api.model.rbac.Subject) RoleRefBuilder(io.fabric8.kubernetes.api.model.rbac.RoleRefBuilder)

Example 19 with SubjectBuilder

use of io.fabric8.kubernetes.api.model.rbac.SubjectBuilder in project strimzi by strimzi.

the class RoleBindingOperatorTest method resource.

@Override
protected RoleBinding resource() {
    Subject ks = new SubjectBuilder().withKind("ServiceAccount").withName("some-service-account").withNamespace(NAMESPACE).build();
    RoleRef roleRef = new RoleRefBuilder().withName("some-role").withApiGroup("rbac.authorization.k8s.io").withKind("ClusterRole").build();
    return new RoleBindingBuilder().withNewMetadata().withName(RESOURCE_NAME).withNamespace(NAMESPACE).withLabels(singletonMap("foo", "bar")).endMetadata().withRoleRef(roleRef).withSubjects(singletonList(ks)).build();
}
Also used : RoleBindingBuilder(io.fabric8.kubernetes.api.model.rbac.RoleBindingBuilder) RoleRef(io.fabric8.kubernetes.api.model.rbac.RoleRef) SubjectBuilder(io.fabric8.kubernetes.api.model.rbac.SubjectBuilder) Subject(io.fabric8.kubernetes.api.model.rbac.Subject) RoleRefBuilder(io.fabric8.kubernetes.api.model.rbac.RoleRefBuilder)

Example 20 with SubjectBuilder

use of io.fabric8.kubernetes.api.model.rbac.SubjectBuilder in project strimzi by strimzi.

the class KafkaCluster method generateClusterRoleBinding.

/**
 * Creates the ClusterRoleBinding which is used to bind the Kafka SA to the ClusterRole
 * which permissions the Kafka init container to access K8S nodes (necessary for rack-awareness).
 *
 * @param assemblyNamespace The namespace.
 * @return The cluster role binding.
 */
public ClusterRoleBinding generateClusterRoleBinding(String assemblyNamespace) {
    if (rack != null || isExposedWithNodePort()) {
        Subject ks = new SubjectBuilder().withKind("ServiceAccount").withName(getServiceAccountName()).withNamespace(assemblyNamespace).build();
        RoleRef roleRef = new RoleRefBuilder().withName("strimzi-kafka-broker").withApiGroup("rbac.authorization.k8s.io").withKind("ClusterRole").build();
        return getClusterRoleBinding(KafkaResources.initContainerClusterRoleBindingName(cluster, namespace), ks, roleRef);
    } else {
        return null;
    }
}
Also used : RoleRef(io.fabric8.kubernetes.api.model.rbac.RoleRef) SubjectBuilder(io.fabric8.kubernetes.api.model.rbac.SubjectBuilder) Subject(io.fabric8.kubernetes.api.model.rbac.Subject) RoleRefBuilder(io.fabric8.kubernetes.api.model.rbac.RoleRefBuilder)

Aggregations

SubjectBuilder (io.fabric8.kubernetes.api.model.rbac.SubjectBuilder)28 RoleRefBuilder (io.fabric8.kubernetes.api.model.rbac.RoleRefBuilder)26 RoleRef (io.fabric8.kubernetes.api.model.rbac.RoleRef)18 Subject (io.fabric8.kubernetes.api.model.rbac.Subject)18 ClusterRoleBindingBuilder (io.fabric8.kubernetes.api.model.rbac.ClusterRoleBindingBuilder)10 RoleBindingBuilder (io.fabric8.kubernetes.api.model.rbac.RoleBindingBuilder)10 RoleBinding (io.fabric8.kubernetes.api.model.rbac.RoleBinding)6 ClusterRoleBinding (io.fabric8.kubernetes.api.model.rbac.ClusterRoleBinding)5 Test (org.junit.jupiter.api.Test)3 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)2 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)2 Role (io.fabric8.kubernetes.api.model.rbac.Role)2 RoleBuilder (io.fabric8.kubernetes.api.model.rbac.RoleBuilder)2 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)2 EnableKubernetesMockClient (io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient)2 ParallelNamespaceTest (io.strimzi.systemtest.annotations.ParallelNamespaceTest)2 KafkaClients (io.strimzi.systemtest.kafkaclients.internalClients.KafkaClients)2 KafkaClientsBuilder (io.strimzi.systemtest.kafkaclients.internalClients.KafkaClientsBuilder)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2