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

auth: Add entitlements to LXD entities (part 1: introduce IsFineGrained field) #14745

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions doc/api-extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -2552,3 +2552,10 @@ This adds support for listing network zones across all projects using the `all-p
Adds support for instance root volumes to be attached to other instances as disk
devices. Introduces the `<type>/<volume>` syntax for the `source` property of
disk devices.

## `entities_with_entitlements`

Adds `fine_grained` field to `GET /1.0/auth/identities/current` to indicate if the current identity
interacting with the LXD API is fine-grained (that is, associated permissions are managed via group membership).
Allows LXD entities to be returned with an `access_entitlements` field if the current identity is fine-grained and the
GET request to fetch the LXD entities has the `with-access-entitlements=<comma_separated_list_of_candidate_entitlements>` query parameter.
6 changes: 6 additions & 0 deletions doc/rest-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,12 @@ definitions:
$ref: '#/definitions/Permission'
type: array
x-go-name: EffectivePermissions
fine_grained:
description: |-
FineGrained is a boolean indicating whether the identity is fine-grained,
meaning that permissions are managed via group membership.
type: boolean
x-go-name: FineGrained
groups:
description: Groups is the list of groups for which the identity is a member.
example:
Expand Down
4 changes: 3 additions & 1 deletion lxd/identities.go
Original file line number Diff line number Diff line change
Expand Up @@ -1126,6 +1126,7 @@ func getCurrentIdentityInfo(d *Daemon, r *http.Request) response.Response {
Identity: *apiIdentity,
EffectiveGroups: effectiveGroups,
EffectivePermissions: effectivePermissions,
FineGrained: identity.IsFineGrainedIdentityType(apiIdentity.Type),
})
}

Expand Down Expand Up @@ -1884,7 +1885,8 @@ func updateIdentityCacheFromLocal(d *Daemon) error {
return fmt.Errorf("Failed reading certificates from local database: %w", err)
}

var identityCacheEntries []identity.CacheEntry
// identityCacheEntries needs to be pre-allocated.
identityCacheEntries := make([]identity.CacheEntry, 0, len(localServerCerts))
for _, dbCert := range localServerCerts {
certBlock, _ := pem.Decode([]byte(dbCert.Certificate))
if certBlock == nil {
Expand Down
4 changes: 4 additions & 0 deletions shared/api/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ type IdentityInfo struct {
// Effective permissions is the combined and deduplicated list of permissions that the identity has by virtue of
// direct membership to a LXD group, or effective membership of a LXD group via identity provider group mappings.
EffectivePermissions []Permission `json:"effective_permissions" yaml:"effective_permissions"`

// FineGrained is a boolean indicating whether the identity is fine-grained,
// meaning that permissions are managed via group membership.
FineGrained bool `json:"fine_grained" yaml:"fine_grained"`
}

// IdentityPut contains the editable fields of an IdentityInfo.
Expand Down
1 change: 1 addition & 0 deletions shared/version/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ var APIExtensions = []string{
"network_get_target",
"network_zones_all_projects",
"instance_root_volume_attachment",
"entities_with_entitlements",
}

// APIExtensionsCount returns the number of available API extensions.
Expand Down
18 changes: 16 additions & 2 deletions test/suites/auth.sh
gabrielmougard marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ groups:
tls_certificate: ""
effective_groups:
- test-group
effective_permissions: []'
effective_permissions: []
fine_grained: true'

[ "$(lxc auth identity info oidc:)" = "${expectedOIDCInfo}" ]

expectedTLSInfo="authentication_method: tls
Expand All @@ -160,7 +162,9 @@ tls_certificate: |
$(awk '{printf " %s\n", $0}' "${LXD_CONF2}/client.crt")
effective_groups:
- test-group
effective_permissions: []"
effective_permissions: []
fine_grained: true"

[ "$(LXD_CONF="${LXD_CONF2}" lxc auth identity info tls:)" = "${expectedTLSInfo}" ]


Expand Down Expand Up @@ -274,6 +278,15 @@ effective_permissions: []"
[ "$(LXD_CONF="${LXD_CONF4}" lxc_remote query tls:/1.0 | jq -r '.auth')" = "trusted" ]
[ "$(LXD_CONF="${LXD_CONF5}" lxc_remote query tls:/1.0 | jq -r '.auth')" = "untrusted" ]

# Check that an unrestricted client certificate is not fine grained.
LXD_CONF6=$(mktemp -d -p "${TEST_DIR}" XXX)
LXD_CONF="${LXD_CONF6}" gen_cert_and_key "unrestricted"
lxdconf6_fingerprint_short="$(cert_fingerprint "${LXD_CONF6}/unrestricted.crt" | head -c12)"
lxc config trust add "${LXD_CONF6}/unrestricted.crt"
lxc config trust show "${lxdconf6_fingerprint_short}" | grep -xF "restricted: false"
[ "$(LXD_CONF="${LXD_CONF6}" CERTNAME=unrestricted my_curl -X GET "https://${LXD_ADDR}/1.0/auth/identities/current" | jq -r .metadata.fine_grained)" = "false" ]
lxc config trust remove "${lxdconf6_fingerprint_short}"

# Cleanup
lxc auth group delete test-group
lxc auth identity-provider-group delete test-idp-group
Expand All @@ -284,6 +297,7 @@ effective_permissions: []"
rm -r "${LXD_CONF3}"
rm -r "${LXD_CONF4}"
rm -r "${LXD_CONF5}"
rm -r "${LXD_CONF6}"
lxc config unset core.remote_token_expiry
lxc config unset oidc.issuer
lxc config unset oidc.client.id
Expand Down
Loading