Search in sources :

Example 36 with Subject

use of io.fabric8.kubernetes.api.model.rbac.Subject 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)

Example 37 with Subject

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

the class KafkaConnectCluster method generateClusterRoleBinding.

/**
 * Creates the ClusterRoleBinding which is used to bind the Kafka Connect SA to the ClusterRole
 * which permissions the Kafka init container to access K8S nodes (necessary for rack-awareness).
 *
 * @return The cluster role binding.
 */
public ClusterRoleBinding generateClusterRoleBinding() {
    if (rack == null) {
        return null;
    }
    Subject subject = new SubjectBuilder().withKind("ServiceAccount").withName(getServiceAccountName()).withNamespace(namespace).build();
    RoleRef roleRef = new RoleRefBuilder().withName("strimzi-kafka-client").withApiGroup("rbac.authorization.k8s.io").withKind("ClusterRole").build();
    return getClusterRoleBinding(KafkaConnectResources.initContainerClusterRoleBindingName(cluster, namespace), subject, roleRef);
}
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)

Example 38 with Subject

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

the class ClusterRoleBindingOperatorIT method getModified.

@Override
protected ClusterRoleBinding getModified() {
    Subject ks = new SubjectBuilder().withKind("ServiceAccount").withName("my-service-account2").withNamespace("my-namespace2").build();
    // RoleRef cannot be changed
    RoleRef roleRef = new RoleRefBuilder().withName("my-cluster-role").withApiGroup("rbac.authorization.k8s.io").withKind("ClusterRole").build();
    return new ClusterRoleBindingBuilder().withNewMetadata().withName(resourceName).withLabels(singletonMap("state", "modified")).endMetadata().withSubjects(ks).withRoleRef(roleRef).build();
}
Also used : RoleRef(io.fabric8.kubernetes.api.model.rbac.RoleRef) ClusterRoleBindingBuilder(io.fabric8.kubernetes.api.model.rbac.ClusterRoleBindingBuilder) 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 39 with Subject

use of io.fabric8.kubernetes.api.model.rbac.Subject in project strimzi-kafka-operator 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 40 with Subject

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

the class EntityTopicOperator 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)

Aggregations

Subject (io.fabric8.kubernetes.api.model.rbac.Subject)24 RoleRef (io.fabric8.kubernetes.api.model.rbac.RoleRef)18 RoleRefBuilder (io.fabric8.kubernetes.api.model.rbac.RoleRefBuilder)18 SubjectBuilder (io.fabric8.kubernetes.api.model.rbac.SubjectBuilder)18 File (java.io.File)15 SecretBuilder (io.fabric8.kubernetes.api.model.SecretBuilder)14 IOException (java.io.IOException)13 Secret (io.fabric8.kubernetes.api.model.Secret)12 CertAndKey (io.strimzi.certs.CertAndKey)12 Subject (io.strimzi.certs.Subject)12 X509Certificate (java.security.cert.X509Certificate)12 Map (java.util.Map)12 RoleBindingBuilder (io.fabric8.kubernetes.api.model.rbac.RoleBindingBuilder)10 CertificateExpirationPolicy (io.strimzi.api.kafka.model.CertificateExpirationPolicy)10 CertManager (io.strimzi.certs.CertManager)10 PasswordGenerator (io.strimzi.operator.common.PasswordGenerator)10 Reconciliation (io.strimzi.operator.common.Reconciliation)10 Base64 (java.util.Base64)10 Function (java.util.function.Function)10 Test (org.testng.annotations.Test)8