Crates.io | mairu |
lib.rs | mairu |
version | 0.1.0 |
source | src |
created_at | 2024-11-01 07:36:04.486395 |
updated_at | 2024-11-01 07:36:04.486395 |
description | on-memory AWS credentials agent and executor |
homepage | https://github.com/sorah/mairu |
repository | https://github.com/sorah/mairu |
max_upload_size | |
id | 1431420 |
size | 297,390 |
Mairu is a tool to securely grant AWS credentials to command-line tools and scripts, with allowing seamless use of multiple AWS roles and accounts concurrently. Mairu can retrieve credentials from AWS SSO (AWS IAM Identity Center), or a credential vending server implements the Mairu API.
By using as a executor, you can seamlessly switch between IAM roles per-project and give explicit intent to allow a command line to access your AWS resources. Plus, Mairu's auto role selector allows reading a desired IAM role from .mairu.json
under your working directory, so you as an admin don't have to tell detailed configuration such as IAM role ARN per project to your colleagues.
Mairu can be used like the following cases. In any case, Mairu automatically retrieves a AWS credential for specified role and prompts user to login when server token is expired or doesn't exist yet.
$ mairu setup-sso my-server --region ${aws_sso_region} --start-url https://my-aws-sso-domain.awsapps.com/start
$ mairu exec --server=my-server 123456789999/AmazingAppDevelopment rails server
or, utilize Mairu's auto
role feature like as follows:
$ echo '{"role": "123456789999/AmazingAppDevelopment", "server": "https://my-aws-sso-domain.awsapps.com/start"}' > my-project/.mairu.json
$ cd my-project
$ mairu exec auto rails server
# ~/.aws/config
[profile mairu_amazing_app]
credential_process = mairu credential-process my-credential-server arn:aws:iam::123456789999:role/AmazingAppDevelopment
then
$ AWS_PROFILE=mairu_amazing_app rails server
cargo install --locked mairu
Mairu reads ~/.config/mairu/servers.d/*.json
for a credential server information:
To quickly generate:
$ mairu setup-sso ${choose_server_id} --region ${aws_sso_region} --start-url https://...awsapps.com/start
Or create by hand:
{
"url": "https://...awsapps.com/start",
"id": "server_id", // Optional, default to {url}
"aws_sso": {
"region": "us-east-1"
}
}
{
"url": "https://cred-server.example.com/", // Trailing slash is important https://docs.rs/url/latest/url/struct.Url.html#method.join
"id": "my-credential-server", // Optional, default to {url}
"oauth": {
"client_id": "...",
"client_secret": "...",
"token_endpoint": "...", // Optional if token_endpoint is at ${url}/oauth/token
"scope": [], // Optional, default to ["profile"]
// Either device_grant or code_grant is required.
// Even if configuration is empty, an empty object (e.g. "code_grant": {}) must be present to denote a support of grant type.
"device_grant": {
"device_authorization_endpoint": "...", // Omit if it is at ${url}/oauth/device
},
"code_grant": {
"authorization_endpoint": "...", // Omit if it is at ${url}/oauth/authorize
"local_port": 16624, // Optional. Static port number to listen for oauth2 redirect_uri, otherwise ephemeral port is assigned and used.
},
"default_grant_type": "code_grant", // Optional
}
}
It is recommended to use the same id
for your entire organisation. Personal preferences can be stored in other location, so it is safe to distribute the servers.d file with MDM or something else.
To learn how to prepare your credential server, continue reading at Credential Server section.
auto
roleMairu treats auto
role as a special mode. It reads closest .mairu.json
file as a JSON object as follows to determine a role to assume:
{
"server": "server id or url to use", // Equivalent to --server cli argument
"role": "role to assume",
"mode": "preferred credential provider method", // optional
}
If it is read by a filesystem, Mairu prompts user to trust that file for the first time. And prompt appears again if the file content has been changed.
We recommend use auto
role by default. This allows using per-project AWS role seamlessly, securely and concurrently! It would also be convenient to have alias ae="mairu exec auto "
in your shell profile.
If your session with a credential server expired, Mairu prompts you to reauthenticate yourself. For existing processes under mairu exec
, you'll see a warning message including a command line to start reauthentication flow.
Mairu supports the following methods to provide credentials to AWS SDK. Choose your best way to pass obtained credentials to your app or tools you love:
ecs
(default): Run ephemeral server to emulate container provider. AWS_CONTAINER_CREDENTIALS_FULL_URI and AWS_CONTAINER_AUTHORIZATION_TOKEN environment variable will be exposed and supports automatic renewal.static
: Expose traditional AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and AWS_SESSION_TOKEN environment variables (static credentials). This method doesn't support automatic renewal, so you have to restart mairu exec
when credentials have expired.<-- TODO: - docker
: Similar to ecs
, but launch a proxy container on Docker to connect Mairu agent from Docker containers. See Docker support for details. AWS_CONTAINER_CREDENTIALS_FULL_URI and AWS_CONTAINER_AUTHORIZATION_TOKEN environment will be exposed and supports automatic renewal. -->
Your preferred method can be specified in --mode
:
$ mariu exec --mode=static auto rails server
Alternatively, you can use Mairu mairu credential-process
command for process credential provider.
Mairu automatically launches agent process in background. This is similar to ssh-agent and gpg-agent. Mairu Agent retains all access tokens for credential server, and caches AWS credentials for re-use on memory.
It listens on $XDG_RUNTIME_DIR/mairu-agent.sock
(or ~/.config/mairu/mairu-agent.sock
) by default.
If you don't have the AWS SSO instance, you need to run your own credential vending server to serve AWS credentials for your Mairu users. You may use a known compatible implementations, or implement your own.
https://aws.amazon.com/iam/identity-center/
.mairu.json
configuration file in a working directory, similar to .{language}-version
files.~/.aws/config
profile for every new role encountered. Mairu can reuse the single configuration (per credential server) for multiple roles and accounts.https://github.com/99designs/aws-vault
.mairu.json
configuration file in a working directory, similar to .{language}-version
files.https://github.com/Netflix/weep
Q. Why Mairu doesn't use OIDC then call sts:AssumeRoleWithWebIdentity directly when retrieving AWS credentials?
A. As this tool aims to allow providing seamless experience for utilizing multiple AWS accounts and roles, an authenticated user is expected to have multiple roles assigned. In that case, it is difficult to allow sts:AssumeRoleWithWebIdentity in AssumeRolePolicy using sub claim because an ID token is likely issued based on user, not a role, and group.
See SECURITY.md.
Similarly to ssh-agent and gpg-agent, this means that Mairu doesn't provide well protection for agent process. Don't run on untrusted machines such like shared machines.
Apache License 2.0
Copyright 2023 Sorah Fukumori.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.