Commit 62a2da2
authored
Add Athenz integration module (#6321)
Motivation:
This PR aims to provide an integration layer for Athenz so that users
can easily obtain Athenz tokens and validate them
by decorating clients or services and annotating required Athenz roles
declaratively.
Modifications:
- Client side
- `ZtsBaseClient` provides common functionality such as `TlsKeyPair`
management and Athenz client configurations.
- Users should create `ZtsBaseClient` first to create `AthenzClient` and
`AthenzService`.
- `ZtsBaseClient` is designed as a resource, and it needs to be closed
since Armeria decorators are not closable.
- The lifecycle of Athenz `ClientFactory` is delegated to
`ZtsBaseClient`
- `AccessTokenClient` acquires OAuth 2.0 token from the`/oauth2/token`
endpoint.
- The cached tokens are automatically refreshed before expiration.
- Athenz uses mTLS as the authorization layer, and the client
credentials of OAuth 2.0 are unnecessary.
- This method does not conform to the official OAuth 2.0 specification.
- `RoleTokenClient` obtains Athenz role tokens from the
`/domain/{domainName}/token?role=<roleName>` endpoint.
- It has a similar refreshing logic to `AccessTokenClient`.
- `AthenzClient` is a public decorator that delegates to
`AccessTokenClient` or `RoleTokenClient` depending on the configuration.
- Server side
- `AthenzPolicyLoader` loads Athenz domain policies from ZTS servers,
just like the `zpu` CLI does.
- The external `zpu` cronjob to fetch policies is no longer necessary.
- Both JWS policy data and signed policy data are supported.
- `AthenzPolicyHandler` parses the policy data and verifies it with
public keys.
- `MinifiedAuthZpeClient` is forked from `AuthZpeClient` and modified to
seamlessly integrate with Armeria.
- `MinifiedAuthZpeClient` is responsible for token validation.
- Reviewers may skip a detailed review of this class.
- `AthenzService` is a public decorator to check access permission for
projected resources.
- `RequiresAthenzRole` allows users to specify an Athenz role using
annotations.
- `AthenzServiceDecoratorFactory` should be injected via
`DependencyInjector` to use `RequiresAthenzRole`
Result:
- You can now use the Athenz module to easily obtain Athenz tokens and
validate them.
- Closes #6050
- Server example:
```java
class MyService {
// 1. Decorate the method with `RequiresAthenzRole` to check Athenz role.
@RequiresAthenzRole(resource = "user", action = "get")
@ProducesJson
@get("/user")
public CompletableFuture<User> getUser() {
...
}
}
// 2. Create a `ZtsBaseClient` and `AthenzServiceDecoratorFactory` to use Athenz.
ZtsBaseClient ztsBaseClient =
ZtsBaseClient
.builder("https://athenz.example.com:4443/zts/v1")
.keyPair("/var/lib/athenz/service.key.pem", "/var/lib/athenz/service.cert.pem")
.build();
final AthenzServiceDecoratorFactory athenzDecoratorFactory =
AthenzServiceDecoratorFactory
.builder(ztsBaseClient)
.policyConfig(new AthenzPolicyConfig("my-domain"))
.build();
// 3. Create a `DependencyInjector` with the `AthenzServiceDecoratorFactory`
// and set it to the server. `AthenzServiceDecoratorFactory` is required to
// create the `RequiresAthenzRole` decorator.
final DependencyInjector di =
DependencyInjector.ofSingletons(athenzDecoratorFactory)
.orElse(DependencyInjector.ofReflective());
serverBuilder.dependencyInjector(di, true);
```
- Client example:
```java
ZtsBaseClient ztsBaseClient =
ZtsBaseClient
.builder("https://athenz.example.com:4443/zts/v1")
.keyPair("/var/lib/athenz/service.key.pem", "/var/lib/athenz/service.cert.pem")
.build();
WebClient
.builder()
.decorator(AthenzClient.newDecorator(ztsBaseClient, "my-domain",
TokenType.ROLE_TOKEN)
...
.build();
```1 parent d562343 commit 62a2da2
File tree
86 files changed
+7115
-14
lines changed- athenz
- src
- main/java/com/linecorp/armeria
- client/athenz
- common/athenz
- internal/common/athenz
- server/athenz
- test
- java/com/linecorp/armeria
- client/athenz
- server/athenz
- resources/docker
- certs
- CAs
- domain-admin
- foo-service-new
- foo-service
- test-service
- zms
- conf
- db
- var
- certs
- keys
- zts
- conf
- db
- var
- certs
- keys
- core/src/main/java/com/linecorp/armeria/server
- oauth2/src/main/java/com/linecorp/armeria/client/auth/oauth2
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
86 files changed
+7115
-14
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
Lines changed: 113 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
Lines changed: 178 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
0 commit comments