|
| 1 | +# A machine token and a person's identity token are both signed by the same |
| 2 | +# provider under the same key, and where a policy names an audience that |
| 3 | +# matches an interactive client's identifier, everything else about them agrees |
| 4 | +# too. RFC 9068 Section 4 has a resource server refuse a token whose `typ` is |
| 5 | +# not the access token profile's, which Section 5 says is what keeps the two |
| 6 | +# apart. A provider that stamps no type cannot be told apart that way, so a |
| 7 | +# policy says which type it requires rather than one being assumed. |
| 8 | +# |
| 9 | +# These two clients differ in exactly that: same realm, same key, same |
| 10 | +# algorithm, same audience, and one stamps the profile's type while the other |
| 11 | +# does not. So a refusal here is attributable to the type alone. |
| 12 | + |
| 13 | +# The client that stamps the type gets a token carrying it |
| 14 | +POST https://keycloak:8443/realms/main/protocol/openid-connect/token |
| 15 | +[FormParams] |
| 16 | +grant_type: client_credentials |
| 17 | +client_id: ci-typed |
| 18 | +client_secret: ci-typed-secret |
| 19 | +HTTP 200 |
| 20 | +[Captures] |
| 21 | +typed_token: jsonpath "$.access_token" |
| 22 | +[Asserts] |
| 23 | +jsonpath "$.token_type" == "Bearer" |
| 24 | +jsonpath "$.access_token" matches /^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/ |
| 25 | + |
| 26 | +# The client that does not stamp it gets one that is otherwise the same |
| 27 | +POST https://keycloak:8443/realms/main/protocol/openid-connect/token |
| 28 | +[FormParams] |
| 29 | +grant_type: client_credentials |
| 30 | +client_id: ci-untyped |
| 31 | +client_secret: ci-untyped-secret |
| 32 | +HTTP 200 |
| 33 | +[Captures] |
| 34 | +untyped_token: jsonpath "$.access_token" |
| 35 | +[Asserts] |
| 36 | +jsonpath "$.token_type" == "Bearer" |
| 37 | + |
| 38 | +# The policy requires the profile's type, so the token carrying it is admitted |
| 39 | +GET {{base}}/typed/thing.json |
| 40 | +Authorization: Bearer {{typed_token}} |
| 41 | +HTTP 200 |
| 42 | +Cache-Control: private, max-age=0, must-revalidate |
| 43 | +Content-Type: application/schema+json |
| 44 | +Link: <https://json-schema.org/draft/2020-12/schema>; rel="describedby" |
| 45 | +Access-Control-Allow-Origin: * |
| 46 | +Access-Control-Expose-Headers: Link, ETag |
| 47 | +[Asserts] |
| 48 | +header "ETag" exists |
| 49 | +{ |
| 50 | + "$schema": "https://json-schema.org/draft/2020-12/schema", |
| 51 | + "$id": "{{base}}/typed/thing", |
| 52 | + "type": "boolean" |
| 53 | +} |
| 54 | + |
| 55 | +# And the one without it is refused, though it is valid in every other respect |
| 56 | +GET {{base}}/typed/thing.json |
| 57 | +Authorization: Bearer {{untyped_token}} |
| 58 | +HTTP 401 |
| 59 | +Cache-Control: no-store |
| 60 | +Content-Type: application/problem+json |
| 61 | +WWW-Authenticate: Bearer realm="registry" |
| 62 | +Link: </self/v1/schemas/api/error>; rel="describedby" |
| 63 | +Access-Control-Allow-Origin: * |
| 64 | +Access-Control-Expose-Headers: Link, ETag |
| 65 | +[Captures] |
| 66 | +denied_body: body |
| 67 | +denied_schema: header "Link" regex "<([^>]+)>" |
| 68 | +[Asserts] |
| 69 | +header "ETag" not exists |
| 70 | +{ |
| 71 | + "type": "urn:sourcemeta:one:authentication-required", |
| 72 | + "title": "Unauthorized", |
| 73 | + "status": 401, |
| 74 | + "detail": "This resource requires authentication" |
| 75 | +} |
| 76 | + |
| 77 | +POST {{base}}/self/v1/api/schemas/evaluate{{denied_schema}} |
| 78 | +``` |
| 79 | +{{denied_body}} |
| 80 | +``` |
| 81 | +HTTP 200 |
| 82 | +[Asserts] |
| 83 | +jsonpath "$.valid" == true |
| 84 | + |
| 85 | +# Carrying nothing is refused identically, so the untyped token discloses |
| 86 | +# nothing by being refused differently |
| 87 | +GET {{base}}/typed/thing.json |
| 88 | +HTTP 401 |
| 89 | +Cache-Control: no-store |
| 90 | +Content-Type: application/problem+json |
| 91 | +WWW-Authenticate: Bearer realm="registry" |
| 92 | +Link: </self/v1/schemas/api/error>; rel="describedby" |
| 93 | +[Asserts] |
| 94 | +body == {{denied_body}} |
| 95 | + |
| 96 | +# The gated listing is not enumerable without the right token either |
| 97 | +GET {{base}}/self/v1/api/list/typed |
| 98 | +Authorization: Bearer {{untyped_token}} |
| 99 | +HTTP 401 |
| 100 | +Cache-Control: no-store |
| 101 | +Content-Type: application/problem+json |
| 102 | +WWW-Authenticate: Bearer realm="registry" |
| 103 | +Link: </self/v1/schemas/api/error>; rel="describedby" |
| 104 | +[Asserts] |
| 105 | +body == {{denied_body}} |
| 106 | + |
| 107 | +# The token that carries the type enumerates it, and the listing names the |
| 108 | +# policy that governs |
| 109 | +GET {{base}}/self/v1/api/list/typed |
| 110 | +Authorization: Bearer {{typed_token}} |
| 111 | +HTTP 200 |
| 112 | +Cache-Control: private, max-age=0, must-revalidate |
| 113 | +Content-Type: application/json |
| 114 | +Link: </self/v1/schemas/api/list/response>; rel="describedby" |
| 115 | +Access-Control-Allow-Origin: * |
| 116 | +Access-Control-Expose-Headers: Link, ETag |
| 117 | +[Captures] |
| 118 | +listing_body: body |
| 119 | +listing_schema: header "Link" regex "<([^>]+)>" |
| 120 | +[Asserts] |
| 121 | +jsonpath "$.path" == "/typed" |
| 122 | +jsonpath "$.url" == "{{base}}/typed" |
| 123 | +jsonpath "$.schemas" == 1 |
| 124 | +jsonpath "$.breadcrumb" count == 1 |
| 125 | +jsonpath "$.breadcrumb[0].name" == "typed" |
| 126 | +jsonpath "$.breadcrumb[0].path" == "/typed/" |
| 127 | +jsonpath "$.policies" count == 1 |
| 128 | +jsonpath "$.policies[0].name" == "typed" |
| 129 | +jsonpath "$.policies[0].title" == "typed" |
| 130 | +jsonpath "$.policies[0].type" == "jwt" |
| 131 | +jsonpath "$.entries" count == 1 |
| 132 | +jsonpath "$.entries[0].name" == "thing" |
| 133 | +jsonpath "$.entries[0].type" == "schema" |
| 134 | +jsonpath "$.entries[0].path" == "/typed/thing" |
| 135 | +jsonpath "$.entries[0].identifier" == "{{base}}/typed/thing" |
| 136 | +jsonpath "$.entries[0].policies" count == 1 |
| 137 | +jsonpath "$.entries[0].policies[0].name" == "typed" |
| 138 | +jsonpath "$.entries[0].policies[0].title" == "typed" |
| 139 | +jsonpath "$.entries[0].policies[0].type" == "jwt" |
| 140 | + |
| 141 | +POST {{base}}/self/v1/api/schemas/evaluate{{listing_schema}} |
| 142 | +``` |
| 143 | +{{listing_body}} |
| 144 | +``` |
| 145 | +HTTP 200 |
| 146 | +[Asserts] |
| 147 | +jsonpath "$.valid" == true |
| 148 | + |
| 149 | +# A policy that requires no type is unaffected, so a provider that stamps none |
| 150 | +# keeps working |
| 151 | +GET {{base}}/machine/config.json |
| 152 | +Authorization: Bearer {{untyped_token}} |
| 153 | +HTTP 401 |
| 154 | +Cache-Control: no-store |
| 155 | +Content-Type: application/problem+json |
| 156 | +WWW-Authenticate: Bearer realm="registry" |
| 157 | +[Asserts] |
| 158 | +body == {{denied_body}} |
0 commit comments