Closed chenkins closed 1 year ago
Problem: we want to avoid sending a token to AssumeRoleWithWebIdentity
that grows with the number of vaults/roles added to the user.
Two options:
(1) Separate client cryptomatorvaults
cryptomator
and cryptomatorhub
cryptomator
and cryptomatorhub
are evaluated in hub REST services for access control (TODO double check this))admin-fine-grained-authz
feature in Keycloak activated as well, as well as a policy allowing cross-client token-exchange to cryptomatorvaults
, see ^1^3audience
parameter in addition.(2) Add vaults to existing clients cryptomator
and cryptomatorhub
admin-fine-grained-authz
feature and corresponding configurationcryptomator
and cryptomatorhub
)Preliminary decision: try out (1) to see how it looks like eventually.
Test for (2):
function jwtd() {
if [[ -x $(command -v jq) ]]; then
jq -R 'split(".") | .[0],.[1] | @base64d | fromjson' <<< "${1}"
echo "Signature: $(echo "${1}" | awk -F'.' '{print $3}')"
fi
}
TOKEN=`curl -v -X POST http://localhost:8180/realms/cryptomator/protocol/openid-connect/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "client_id=cryptomator" \
-d "scope=openid" \
-d "grant_type=password" \
-d "username=admin" \
-d "password=admin" | jq ".access_token" | tr -d '"'`
jwtd $TOKEN
SCOPED_TOKEN=`curl -X POST http://localhost:8180/realms/cryptomator/protocol/openid-connect/token\
-d "client_id=cryptomator" \
--data-urlencode "grant_type=urn:ietf:params:oauth:grant-type:token-exchange" \
-d "subject_token=$TOKEN" \
-d "subject_issuer=http://localhost:8180/realms/cryptomator" \
--data-urlencode "subject_token_type=urn:ietf:params:oauth:token-type:access_token" \
-d "audience=cryptomatorvaults" \
-d "scope=openid c1089d35-0abe-4e51-ab58-ed8c1507efca" | jq ".access_token" | tr -d '"'`
jwtd $SCOPED_TOKEN
Problem: the token we create buckets with has all realm and client roles mapped into it by default. Two options:
(1) additional token-exchange before creating buckets using cryptomator
or cryptomatorhub
client
Keycloak.js
or additional OIDC client, see https://github.com/keycloak/keycloak/discussions/17018. See also started snippet below.cryptomator
and cryptomatorhub
clients.(2) patch dev-realm.json
:
cryptomatorvaults
only, so this seems a straightforward separation as long as there is no future usage of client roles for other purposes.cryptomator
and cryptomatorhub
clients in dev-realm.json
.-> Let's go for (2) as long as there is no conflict with this approach.
Snippets for patching Keycloak.js
(unfinished business):
public async tokenExchange(): string{
this.keycloak.tokenExchange = function(){
var kc = this;
var params = 'grant_type=urn:ietf:params:oauth:grant-type:token-exchange"&' + 'subject_token=' + kc.accessToken;
return new Promise(function (resolve, reject) {
var url = kc.endpoints.token();
var req = new XMLHttpRequest();
req.open('POST', url, true);
req.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
req.withCredentials = true;
params += '&client_id=' + encodeURIComponent(kc.clientId);
var timeLocal = new Date().getTime();
req.onreadystatechange = function () {
if (req.readyState == 4) {
if (req.status == 200) {
console.log('[KEYCLOAK] Token refreshed');
timeLocal = (timeLocal + new Date().getTime()) / 2;
var tokenResponse = JSON.parse(req.responseText);
kc.onAuthRefreshSuccess && kc.onAuthRefreshSuccess();
resolve(tokenResponse['access_token'], tokenResponse['refresh_token'], tokenResponse['id_token'], timeLocal);
} else {
console.log('[KEYCLOAK] Failed to refresh token');
if (req.status == 400) {
kc.clearToken();
}
kc.onAuthRefreshError && kc.onAuthRefreshError();
reject();
}
}
};
req.send(params);
});
};
await this.keycloak.tokenExchange();
return this.keycloak.token;
}
N.B. Without roles.client.realm-management
in dev-realm.json
, we get:
2023-11-20 14:01:40 2023-11-20 13:01:40,731 ERROR [org.keycloak.services.error.KeycloakErrorHandler] (executor-thread-1) Uncaught server error: java.lang.RuntimeException: Unable to find composite client role: realm-admin
Story
Acceptance Criteria
dev-realm.json
: which claim is required in hub for user role etc.? As users get one role per shared vault, this should not grow in access token!dev-realm.json
clientscryptomatorvaults
andrealm-management
Open Questions
Context
Implementation