-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #512 from splitgraph/oidc-sts-test
Extend assume role tests
- Loading branch information
Showing
8 changed files
with
167 additions
and
38 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Mock Dex OIDC config, appropriated from the example config: | ||
# https://github.com/dexidp/dex/blob/master/examples/config-dev.yaml | ||
|
||
# The base path of dex and the external name of the OpenID Connect service. | ||
# This is the canonical URL that all clients MUST use to refer to dex. If a | ||
# path is provided, dex's HTTP service will listen at a non-root URL. | ||
issuer: http://dex:5556/dex | ||
|
||
# The storage configuration determines where dex stores its state. Supported | ||
# options include SQL flavors and Kubernetes third party resources. | ||
# | ||
# See the documentation (https://dexidp.io/docs/storage/) for further information. | ||
storage: | ||
type: sqlite3 | ||
config: | ||
file: ":memory:" | ||
|
||
# Configuration for the HTTP endpoints. | ||
web: | ||
http: 0.0.0.0:5556 | ||
|
||
oauth2: | ||
# Uncomment the passwordConnector to use a specific connector for password grants | ||
passwordConnector: local | ||
|
||
# Instead of reading from an external storage, use this list of clients. | ||
# | ||
# If this option isn't chosen clients may be added through the gRPC API. | ||
staticClients: | ||
- id: example-app | ||
redirectURIs: | ||
- "http://dex:5555/callback" | ||
name: "Example App" | ||
secret: ZXhhbXBsZS1hcHAtc2VjcmV0 | ||
|
||
connectors: | ||
- type: mockCallback | ||
id: mock | ||
name: Example | ||
|
||
# Let dex keep a list of passwords which can be used to login to dex. | ||
enablePasswordDB: true | ||
|
||
# A static list of passwords to login the end user. By identifying here, dex | ||
# won't look in its underlying storage for passwords. | ||
# | ||
# If this option isn't chosen users may be added through the gRPC API. | ||
staticPasswords: | ||
- email: "[email protected]" | ||
# bcrypt hash of the string "password": $(echo password | htpasswd -BinC 10 admin | cut -d: -f2) | ||
hash: "$2a$10$2b2cU8CPhOTaGrs1HRQuAueS7JTT5ZHsHSzYiFPm1leZck7Mc8T4W" | ||
# Important bit here, the test pass because this username equals a pre-set MinIO policy (and claim name | ||
# is set to name above). | ||
username: "readwrite" | ||
userID: "08a8684b-db88-4b73-90a9-3cd1661f5466" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,9 @@ | |
|
||
use arrow_flight::FlightClient; | ||
use assert_cmd::prelude::*; | ||
use aws_credential_types::provider::SharedCredentialsProvider; | ||
use aws_credential_types::Credentials; | ||
use aws_sdk_sts::config::ProvideCredentials; | ||
use aws_sdk_sts::Client; | ||
use rstest::fixture; | ||
use seafowl::config::schema::{load_config_from_string, SeafowlConfig}; | ||
use std::collections::HashMap; | ||
|
@@ -145,30 +146,81 @@ async fn get_addr() -> SocketAddr { | |
.unwrap() | ||
} | ||
|
||
// Get temporary creds for a specific role in MinIO | ||
async fn get_sts_creds() -> (String, String, String) { | ||
let root_creds = Credentials::from_keys("minioadmin", "minioadmin", None); | ||
|
||
let config = aws_config::SdkConfig::builder() | ||
.region(aws_config::Region::new("us-east-1")) | ||
.endpoint_url("http://localhost:9000") | ||
.time_source(aws_smithy_async::time::SystemTimeSource::new()) | ||
.build(); | ||
|
||
let provider = aws_config::sts::AssumeRoleProvider::builder("test-user") | ||
.session_name("test-session") | ||
.configure(&config) | ||
.build_from_provider(root_creds) | ||
.await; | ||
|
||
let creds = provider | ||
.provide_credentials() | ||
.await | ||
.expect("MinIO STS credentials provided"); | ||
enum AssumeRoleTarget { | ||
MinioUser, | ||
DexOIDC, | ||
} | ||
|
||
( | ||
creds.access_key_id().to_string(), | ||
creds.secret_access_key().to_string(), | ||
creds.session_token().expect("Token present").to_string(), | ||
) | ||
// Get temporary creds for a specific role in MinIO. The hard-coded configs stem from the | ||
// values used in the `docker-compose.yml` file. | ||
async fn get_sts_creds(role: AssumeRoleTarget) -> (String, String, String) { | ||
match role { | ||
AssumeRoleTarget::MinioUser => { | ||
let root_creds = Credentials::from_keys("minioadmin", "minioadmin", None); | ||
|
||
let config = aws_config::SdkConfig::builder() | ||
.credentials_provider(SharedCredentialsProvider::new(root_creds)) | ||
.region(aws_config::Region::new("us-east-1")) | ||
.endpoint_url("http://localhost:9000") | ||
.build(); | ||
|
||
let creds = Client::new(&config) | ||
.assume_role() | ||
.role_arn("test-user") | ||
.send() | ||
.await | ||
.unwrap() | ||
.credentials | ||
.expect("MinIO STS credentials provided"); | ||
|
||
( | ||
creds.access_key_id, | ||
creds.secret_access_key, | ||
creds.session_token, | ||
) | ||
} | ||
AssumeRoleTarget::DexOIDC => { | ||
let client = reqwest::Client::new(); | ||
|
||
// Get a token from Dex | ||
let url = "http://localhost:5556/dex/token"; | ||
let params = [ | ||
("grant_type", "password"), | ||
("client_id", "example-app"), | ||
("client_secret", "ZXhhbXBsZS1hcHAtc2VjcmV0"), | ||
("username", "[email protected]"), | ||
("password", "password"), | ||
("scope", "groups openid profile email offline_access"), | ||
]; | ||
let response = client.post(url).form(¶ms).send().await.unwrap(); | ||
|
||
let status = response.status(); | ||
let body = response.text().await.unwrap(); | ||
assert_eq!(status, 200, "Dex token request failed: {body}"); | ||
let res: serde_json::Value = serde_json::from_str(&body).unwrap(); | ||
let dex_token = res.get("access_token").expect("token present"); | ||
|
||
// Exchange Dex token for valid MinIO STS credentials using the AssumeRoleWithWebIdentity | ||
// action. | ||
let config = aws_config::SdkConfig::builder() | ||
.region(aws_config::Region::new("us-east-1")) | ||
.endpoint_url("http://localhost:9000") | ||
.build(); | ||
|
||
let creds = Client::new(&config) | ||
.assume_role_with_web_identity() | ||
.web_identity_token(dex_token.as_str().unwrap()) | ||
.send() | ||
.await | ||
.unwrap() | ||
.credentials | ||
.expect("MinIO STS credentials provided"); | ||
|
||
( | ||
creds.access_key_id, | ||
creds.secret_access_key, | ||
creds.session_token, | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters