Documentation ¶
Index ¶
- Constants
- Variables
- func ClusterRoleBindingNode(clusterRoleBindingName string) zanzibar.Node
- func ClusterRoleLabelAggregationKeyNode(key string) zanzibar.Node
- func ClusterRoleLabelAggregationKeyValueNode(key, value string) zanzibar.Node
- func ClusterRoleLabelAggregationNodes(key, value string) zanzibar.Nodes
- func ClusterRoleNode(clusterRoleName string) zanzibar.Node
- func EscapedNode(typeName, instanceName string) zanzibar.Node
- func GetSchema() zanzibar.AuthorizationSchema
- func GroupNode(groupname string) zanzibar.Node
- func NamespaceNode(namespace string) zanzibar.Node
- func NamespacedRoleBindingNode(namespaceName, roleBindingName string) zanzibar.Node
- func NamespacedRoleNode(namespaceName, roleName string) zanzibar.Node
- func NonResourceNode(nonResourceURL string) zanzibar.Node
- func ResourceInstanceNode(apiGroup, resource, instanceName string) zanzibar.Node
- func ResourceNode(apiGroup, resource string) zanzibar.Node
- func TypedNode(typeName, instanceName string) zanzibar.Node
- func UserNode(username string) zanzibar.Node
- type GenericConverter
- func (GenericConverter) ConvertClusterRoleBindingToTuples(ctx context.Context, clusterrolebinding rbacv1.ClusterRoleBinding) ([]Tuple, error)
- func (GenericConverter) ConvertClusterRoleToTuples(ctx context.Context, clusterrole rbacv1.ClusterRole) ([]zanzibar.Tuple, error)
- func (GenericConverter) ConvertRoleBindingToTuples(ctx context.Context, rolebinding rbacv1.RoleBinding) ([]Tuple, error)
- func (GenericConverter) ConvertRoleToTuples(ctx context.Context, role rbacv1.Role) ([]Tuple, error)
- type RBACTupleConverter
- type Tuple
Constants ¶
const ( // TODO: Compile these constants into the DSL authz model directly TypeUser = "user" TypeGroup = "group" TypeClusterRole = "clusterrole" TypeClusterRoleBinding = "clusterrolebinding" TypeNamespacedRole = "role" TypeNamespacedRoleBinding = "rolebinding" TypeNamespace = "namespace" // TODO: this should be called resource collection or something like object and collection scoped terminology TypeResource = "resource" TypeNonResource = "nonresourceurls" TypeClusterRoleLabelAggregation = "clusterrole_label" TypeResourceInstance = "resourceinstance" RBACMatchAllVerbs = rbacv1.VerbAll // ZanzibarMatchAllNonResources = "/*" RelationResourceAnyVerb = "anyverb" // RelationClusterRoleLabelSelector specifies the relation when "clusterrole:edit#assignee selects clusterrole_label:aggregate-to-edit=true" // TODO: Unify these with the other ZanzibarRelation... names RelationClusterRoleLabelSelector = "selects" // RelationClusterRoleAssignee specifies the relation between some kind of user, group or userset of user or group type, e.g. // - "user:lucas assignee clusterrole:foo" // - "group:admin assignee clusterrole:admin" // - "clusterrole_label:aggregate-to-edit=true#selected assignee clusterrole:my-aggregated-edit-role" // - "clusterrole:admin#assignee assignee clusterrole:view" RelationClusterRoleAssignee = "assignee" // RelationNamespacedRoleAssignee defines what relation a user and group can have to the role, in order to be matched for getting privileges // like read and write access to namespaced APIs, e.g. // - "role:foo#assignee is related to resource:core.pods as get" RelationNamespacedRoleAssignee = "assignee" RelationNamespacedRoleNamespacedAssignee = "namespaced_assignee" // RelationNamespaceContainsRole defines the relation between a role and its namespace RelationNamespaceContainsRole = "contains" ContextualRelationWildcardMatch = "wildcardmatch" ContextualRelationOperatesInNamespace = "operates_in" ContextualRelationResourceMatch = "resourcematch" ContextualRelationUserInGroup = "members" APIGroupKubernetesCore = "core" KindClusterRole = "ClusterRole" KindClusterRoleBinding = "ClusterRoleBinding" KindRole = "Role" )
Variables ¶
var ( // TODO: distinguish between what can be asked for in authorizer or specified in RBAC InstanceRelationsOnly = sets.New[string]() // TODO: "impersonate", "approve", "sign", "attest" // These are not used in the API server, only in Authorizer APIs/SARs CollectionRelationsOnly = sets.New("list", "create", "deletecollection") CommonRelations = sets.New("get", "watch", "update", "patch", "delete") // TODO: Do we have to add "proxy" as well? InstanceRelations = InstanceRelationsOnly.Union(CommonRelations) CollectionRelations = CollectionRelationsOnly.Union(CommonRelations) ResourceRelations = CommonRelations.Union(InstanceRelationsOnly).Union(CollectionRelationsOnly) NonResourceRelations = sets.New("get") )
Functions ¶
func ClusterRoleBindingNode ¶
func ClusterRoleNode ¶
func EscapedNode ¶
EscapedNode escapes the instance name for resources with sloppy specifications; like RBAC names
func GetSchema ¶
func GetSchema() zanzibar.AuthorizationSchema
func GroupNode ¶
GroupNode returns the node name for a group node TODO: Do we really have to escape this? Are there any guarantees for group names? Probably not
func NamespaceNode ¶
TODO: I'm pretty sure namespaces only can have sensible DNS1123 label conformant names and thus don't need escaping
func NamespacedRoleNode ¶
NamespacedRoleNode returns the zanzibar node for a namespaced role. As it is namespaced, it is fully qualified only with a given namespace. Only the role name is escaped in openfga, the namespace is known to be ok.
func NonResourceNode ¶
NonResourceNode escapes the tuple name, as the path is not validated in Kubernetes and can be anything, including have whitespace and ":" TODO: Validate this properly, and don't escape. In OpenFGA, a "/" prefix is always enforced, thus "*" in Kubernetes maps to "/*" in OpenFGA.
func ResourceInstanceNode ¶
TODO: verify that query escaping here is ok TODO: need namespace here too
func ResourceNode ¶
ResourceNode returns the node for resource requests, such as "resource:core.pods", to which a user can have e.g. a get relation to. "resource:*.pods", "resource:apps.*" and "resource:*.*" are also possible. No query escaping takes place here.
Types ¶
type GenericConverter ¶
type GenericConverter struct { }
func (GenericConverter) ConvertClusterRoleBindingToTuples ¶
func (GenericConverter) ConvertClusterRoleBindingToTuples(ctx context.Context, clusterrolebinding rbacv1.ClusterRoleBinding) ([]Tuple, error)
func (GenericConverter) ConvertClusterRoleToTuples ¶
func (GenericConverter) ConvertClusterRoleToTuples(ctx context.Context, clusterrole rbacv1.ClusterRole) ([]zanzibar.Tuple, error)
func (GenericConverter) ConvertRoleBindingToTuples ¶
func (GenericConverter) ConvertRoleBindingToTuples(ctx context.Context, rolebinding rbacv1.RoleBinding) ([]Tuple, error)
func (GenericConverter) ConvertRoleToTuples ¶
type RBACTupleConverter ¶
type RBACTupleConverter interface { // ConvertClusterRoleToTuples produces Tuples related to the given ClusterRole. The tuples are produced // as following: // - One incoming Tuple from clusterrole_label#selected through the assignee relation per label // - One outgoing Tuple from clusterrole#assignee to the clusterrole_label type through the selected relation // - Per Resource Rule OR // - len(apiGroups)*len(verbs)*len(resources) outgoing tuples from clusterrole#assignee to resource type // through the relation related to the verb, OR // - len(apiGroups)*len(verbs)*len(resources)*len(resourceNames) outgoing tuples from clusterrole#assignee // to the resourceinstance type through the relation related to the verb // - Per Non-resource Rule: // - len(nonResourceURLs)*len(verbs) outgoing tuples from clusterrole#assignee to the nonresourceurls type // through the relation related to the verb ConvertClusterRoleToTuples(ctx context.Context, clusterrole rbacv1.ClusterRole) ([]Tuple, error) // ConvertRoleToTuples produces Tuples related to the given ClusterRole. The tuples are produced // as following: // - One incoming Tuple from clusterrole_label#selected through the assignee relation per label // - One outgoing Tuple from clusterrole#assignee to the clusterrole_label type through the selected relation // - Per Resource Rule OR // - len(apiGroups)*len(verbs)*len(resources) outgoing tuples from clusterrole#assignee to resource type // through the relation related to the verb, OR // - len(apiGroups)*len(verbs)*len(resources)*len(resourceNames) outgoing tuples from clusterrole#assignee // to the resourceinstance type through the relation related to the verb // - Per Non-resource Rule: // - len(nonResourceURLs)*len(verbs) outgoing tuples from clusterrole#assignee to the nonresourceurls type // through the relation related to the verb // TODO: Finish this documentation for all methods ConvertRoleToTuples(ctx context.Context, role rbacv1.Role) ([]Tuple, error) // RolesBinding ConvertClusterRoleBindingToTuples(ctx context.Context, clusterrolebinding rbacv1.ClusterRoleBinding) ([]Tuple, error) ConvertRoleBindingToTuples(ctx context.Context, rolebinding rbacv1.RoleBinding) ([]Tuple, error) }
TODO: With or without pointers?