Skip to content
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

Allow registry username to reference a secret #91

Merged
merged 3 commits into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,14 @@ The default registry is Docker Hub, but you can change it using `registry/server
```yaml
registry:
server: registry.digitalocean.com
username: registry-user-name
password: <%= ENV.fetch("MRSK_REGISTRY_PASSWORD") %>
username:
- DOCKER_REGISTRY_TOKEN
password:
- DOCKER_REGISTRY_TOKEN
```

A reference to secret `DOCKER_REGISTRY_TOKEN` will look for `ENV["DOCKER_REGISTRY_TOKEN"]` on the machine running MRSK.

### Using a different SSH user than root

The default SSH user is root, but you can change it using `ssh/user`:
Expand Down
10 changes: 5 additions & 5 deletions lib/mrsk/commands/registry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ class Mrsk::Commands::Registry < Mrsk::Commands::Base
delegate :registry, to: :config

def login
docker :login, registry["server"], "-u", redact(registry["username"]), "-p", redact(lookup_password)
docker :login, registry["server"], "-u", redact(lookup("username")), "-p", redact(lookup("password"))
end

def logout
docker :logout, registry["server"]
end

private
def lookup_password
if registry["password"].is_a?(Array)
ENV.fetch(registry["password"].first).dup
def lookup(key)
if registry[key].is_a?(Array)
ENV.fetch(registry[key].first).dup
else
registry["password"]
registry[key]
end
end
end
11 changes: 11 additions & 0 deletions test/commands/registry_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ class CommandsRegistryTest < ActiveSupport::TestCase
ENV.delete("MRSK_REGISTRY_PASSWORD")
end

test "registry login with ENV username" do
ENV["MRSK_REGISTRY_USERNAME"] = "also-secret"
@config[:registry]["username"] = [ "MRSK_REGISTRY_USERNAME" ]

assert_equal \
"docker login hub.docker.com -u also-secret -p secret",
@registry.login.join(" ")
ensure
ENV.delete("MRSK_REGISTRY_USERNAME")
end

test "registry logout" do
assert_equal \
"docker logout hub.docker.com",
Expand Down