-
Notifications
You must be signed in to change notification settings - Fork 27
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
Add github authentication #74
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -271,6 +271,16 @@ echo token=$token | |
kubectl get secret $secret_name -o json | jq -r '.data."ca.crt"' | base64 -D > /tmp/ca.crt | ||
---- | ||
|
||
== GitHub Authentication | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can add a bullet point in the list given at the beginning. |
||
|
||
The GitHub authentication rely on a token with the `admin:org->read:org` scope generated from https://github.com/settings/tokens/new. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo: relies |
||
|
||
The application can be configured to login with that token using the property: | ||
[source, properties, subs=attributes+] | ||
---- | ||
quarkus.vault.authentication.github.token=gh_token | ||
---- | ||
|
||
=== Vault | ||
|
||
The next step requires to exec interactively with the root token into the Vault container | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package io.quarkus.vault; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import org.eclipse.microprofile.config.inject.ConfigProperty; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.quarkus.test.common.QuarkusTestResource; | ||
|
||
@QuarkusTestResource(WiremockVault.class) | ||
public class VaultGithubTCase { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addAsResource("application-vault-github.properties", "application.properties")); | ||
|
||
@ConfigProperty(name = "quarkus.vault.authentication.github.token") | ||
String token; | ||
|
||
@Test | ||
public void testToken() { | ||
assertEquals("123", token); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
quarkus.vault.url=https://localhost:8201 | ||
quarkus.vault.enterprise.namespace=accounting | ||
quarkus.vault.authentication.github.token=123 | ||
quarkus.vault.kv-secret-engine-version=1 | ||
quarkus.tls.trust-all=true |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package io.quarkus.vault.runtime.client.dto.auth; | ||
|
||
import io.quarkus.vault.runtime.client.dto.AbstractVaultDTO; | ||
|
||
/* | ||
|
||
{ | ||
"request_id": "266bffba-8851-cfd2-dd2a-a230655c6f2b", | ||
"lease_id": "", | ||
"renewable": false, | ||
"lease_duration": 0, | ||
"data": null, | ||
"wrap_info": null, | ||
"warnings": null, | ||
"auth": { | ||
"client_token": "s.tmaYRmdXqKVF810aYOinWgMd", | ||
"accessor": "PAwVe79bWN0uoGCLrWdfYsIR", | ||
"policies": [ | ||
"default", | ||
"mypolicy" | ||
], | ||
"token_policies": [ | ||
"default", | ||
"mypolicy" | ||
], | ||
"metadata": { | ||
"username": "bob", | ||
"org": "obo" | ||
}, | ||
"lease_duration": 43200, | ||
"renewable": true, | ||
"entity_id": "f0289e14-f9ac-a5e0-c1df-88d8d031bf38", | ||
"token_type": "service", | ||
"orphan": true | ||
} | ||
} | ||
|
||
*/ | ||
public class VaultUserGitHubAuth extends AbstractVaultDTO<Object, VaultUserGitHubAuthAuth> { | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package io.quarkus.vault.runtime.client.dto.auth; | ||
|
||
public class VaultUserGitHubAuthAuth extends AbstractVaultAuthAuth<VaultUserGitHubAuthAuthMetadata> { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package io.quarkus.vault.runtime.client.dto.auth; | ||
|
||
import io.quarkus.vault.runtime.client.dto.VaultModel; | ||
|
||
public class VaultUserGitHubAuthAuthMetadata implements VaultModel { | ||
|
||
public String username; | ||
|
||
public String org; | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package io.quarkus.vault.runtime.client.dto.auth; | ||
|
||
import io.quarkus.vault.runtime.client.dto.VaultModel; | ||
|
||
public class VaultUserGitHubAuthBody implements VaultModel { | ||
|
||
public VaultUserGitHubAuthBody(String token) { | ||
this.token = token; | ||
} | ||
|
||
public String token; | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package io.quarkus.vault.runtime.client.authmethod; | ||
|
||
import javax.inject.Singleton; | ||
|
||
import io.quarkus.vault.runtime.client.VaultClient; | ||
import io.quarkus.vault.runtime.client.VaultInternalBase; | ||
import io.quarkus.vault.runtime.client.dto.auth.VaultUserGitHubAuth; | ||
import io.quarkus.vault.runtime.client.dto.auth.VaultUserGitHubAuthBody; | ||
import io.smallrye.mutiny.Uni; | ||
|
||
@Singleton | ||
public class VaultInternalGitHubAuthMethod extends VaultInternalBase { | ||
|
||
@Override | ||
protected String opNamePrefix() { | ||
return super.opNamePrefix() + " [AUTH (GitHub token)]"; | ||
} | ||
|
||
public Uni<VaultUserGitHubAuth> login(VaultClient vaultClient, String token) { | ||
VaultUserGitHubAuthBody body = new VaultUserGitHubAuthBody(token); | ||
return vaultClient.post(opName("Login"), "auth/github/login", null, body, VaultUserGitHubAuth.class); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package io.quarkus.vault.runtime.config; | ||
|
||
import java.util.Optional; | ||
|
||
import io.quarkus.runtime.annotations.ConfigGroup; | ||
import io.quarkus.runtime.annotations.ConfigItem; | ||
|
||
@ConfigGroup | ||
public class VaultGitHubAuthenticationConfig { | ||
|
||
/** | ||
* Token for GitHub auth method. This property is required when selecting the github authentication type. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we don't choose, do we? it is implicit when we set this attribute. correct? |
||
*/ | ||
@ConfigItem | ||
public Optional<String> token; | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to add this as part of the PR @gastaldi ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, please add it in a separate PR using the
@all-contributors add @r00ta for code
command (which can be triggered by a comment in this PR)