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

fix: encode op "URI" as base64 #1037

Merged
merged 1 commit into from
Mar 7, 2024
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
2 changes: 2 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
set positional-arguments

# Start a hot-reloading dev cluster
dev: install-jars
goreman -logtime=false start
Expand Down
18 changes: 13 additions & 5 deletions common/configuration/1password.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package configuration
import (
"bytes"
"context"
"encoding/base64"
"encoding/json"
"fmt"
"net/url"
"strings"

"github.com/TBD54566975/ftl/internal/exec"
"github.com/TBD54566975/ftl/internal/log"
Expand All @@ -27,7 +29,13 @@ func (o OnePasswordProvider) Load(ctx context.Context, ref Ref, key *url.URL) ([
if err != nil {
return nil, fmt.Errorf("1Password CLI tool \"op\" not found: %w", err)
}
output, err := exec.Capture(ctx, ".", "op", "read", "-n", key.String())

decoded, err := base64.RawStdEncoding.DecodeString(key.Host)
if err != nil {
return nil, fmt.Errorf("1Password secret reference must be a base64 encoded string: %w", err)
}

output, err := exec.Capture(ctx, ".", "op", "read", "-n", string(decoded))
if err != nil {
lines := bytes.Split(output, []byte("\n"))
logger := log.FromContext(ctx)
Expand All @@ -44,11 +52,11 @@ func (o OnePasswordProvider) Store(ctx context.Context, ref Ref, value []byte) (
if err := json.Unmarshal(value, &opref); err != nil {
return nil, fmt.Errorf("1Password value must be a JSON string containing a 1Password secret refererence: %w", err)
}
u, err := url.Parse(opref)
if err != nil {
return nil, fmt.Errorf("invalid 1Password item ID: %w", err)
if !strings.HasPrefix(opref, "op://") {
return nil, fmt.Errorf("1Password secret reference must start with \"op://\"")
}
return u, nil
encoded := base64.RawStdEncoding.EncodeToString([]byte(opref))
return &url.URL{Scheme: "op", Host: encoded}, nil
}

func (o OnePasswordProvider) Writer() bool { return o.OnePassword }