Skip to content
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 cmd/livepeer/testdata/cli/orchestrator-help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Flags:
--bootstrap-secret-file string File containing runner bootstrap credential (env: LIVEPEER_ORCHESTRATOR_BOOTSTRAP_SECRET_FILE)
--runner-config string Static runner TOML path (env: LIVEPEER_ORCHESTRATOR_RUNNER_CONFIG)
--redeemer-url string Remote winning-ticket redeemer base URL (env: LIVEPEER_ORCHESTRATOR_REDEEMER_URL)
--redeemer-headers-file string Owner-only ticket submission headers file (env: LIVEPEER_ORCHESTRATOR_REDEEMER_HEADERS_FILE)
--redeemer-grants strings Private remote redeemer IP[:port] or CIDR grants (env: LIVEPEER_ORCHESTRATOR_REDEEMER_GRANTS)
--max-pending-tickets int Maximum unsettled winning tickets (env: LIVEPEER_ORCHESTRATOR_MAX_PENDING_TICKETS) (default 100000)
--max-tickets-per-recipient int Maximum unsettled tickets per recipient (env: LIVEPEER_ORCHESTRATOR_MAX_TICKETS_PER_RECIPIENT) (default 10000)
Expand Down Expand Up @@ -57,5 +58,6 @@ Use "livepeer-orchestrator [command] --help" for more information about a comman

Environment Variables:
LIVEPEER_ORCHESTRATOR_BOOTSTRAP_SECRET Dynamic runner bootstrap credential
LIVEPEER_ORCHESTRATOR_REDEEMER_HEADERS Headers authenticating winning-ticket submission
LIVEPEER_ORCHESTRATOR_KEYSTORE_PASSWORD Keystore decryption password
LIVEPEER_ORCHESTRATOR_RPC_URL
6 changes: 6 additions & 0 deletions docs/orchestrator.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,9 @@ forward durable winning tickets without unlocking an orchestrator wallet. Keep
the payment database and chain/pricing settings; remove local wallet and
transaction settings. Local redemption remains the default. See the
[standalone redeemer guide](redeemer.md) for setup, capacity, and recovery.

Remote ticket submission may authenticate with `RedeemerHeadersFile`, an owner-only
regular file using comma-separated `Header: value` entries, for example
`Authorization: Bearer <submission credential>`. `RedeemerHeaders` is also accepted
through secret configuration conventions. These headers are used only for the
configured no-redirect redemption destination and are omitted from printed config.
18 changes: 17 additions & 1 deletion orchestrator/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"net"
"net/http"
"net/url"
"os"
"os/signal"
"strings"
"sync"
Expand Down Expand Up @@ -48,6 +49,8 @@ type Params struct {
BootstrapSecretFile string `basepath:"source" secretfor:"BootstrapSecret" descr:"File containing runner bootstrap credential"`
RunnerConfig string `basepath:"source" optional:"true" file:"true" descr:"Static runner TOML path"`
RedeemerURL *url.URL `name:"redeemer-url" optional:"true" descr:"Remote winning-ticket redeemer base URL"`
RedeemerHeaders nodeconfig.Headers `optional:"true" secret:"true" descr:"Headers authenticating winning-ticket submission"`
RedeemerHeadersFile string `basepath:"source" secretfor:"RedeemerHeaders" descr:"Owner-only ticket submission headers file"`
RedeemerGrants []string `optional:"true" descr:"Private remote redeemer IP[:port] or CIDR grants"`
MaxPendingTickets int `default:"100000" min:"1" descr:"Maximum unsettled winning tickets"`
MaxTicketsPerRecipient int `default:"10000" min:"1" descr:"Maximum unsettled tickets per recipient"`
Expand Down Expand Up @@ -79,6 +82,19 @@ func (p Params) paymentsRequested() bool {
}

func (p Params) Validate() error {
if _, err := p.RedeemerHeaders.MarshalText(); err != nil {
return errors.New("invalid redemption submission headers")
}
if (len(p.RedeemerHeaders) > 0 || p.RedeemerHeadersFile != "") && p.RedeemerURL == nil {
return errors.New("redemption submission headers require remote redemption")
}
if p.RedeemerHeadersFile != "" {
info, err := os.Stat(p.RedeemerHeadersFile)
if err != nil || !info.Mode().IsRegular() || info.Mode().Perm()&0077 != 0 {
return errors.New("redemption header file must be an owner-only regular file")
}
}

if p.BootstrapSecret == "" && p.RunnerConfig == "" {
return errors.New("bootstrap secret or static runner config is required: set LIVEPEER_ORCHESTRATOR_BOOTSTRAP_SECRET, supply --bootstrap-secret-file (or LIVEPEER_ORCHESTRATOR_BOOTSTRAP_SECRET_FILE), or supply --runner-config (or LIVEPEER_ORCHESTRATOR_RUNNER_CONFIG) with a static runner TOML file")
}
Expand Down Expand Up @@ -453,7 +469,7 @@ func Serve(parent context.Context, p Params, logOut io.Writer) (result error) {
if e != nil {
return e
}
remote, e := redemption.NewHTTPDestination(p.RedeemerURL, policy, binding)
remote, e := redemption.NewHTTPDestination(p.RedeemerURL, policy, binding, http.Header(p.RedeemerHeaders))
if e != nil {
return e
}
Expand Down
19 changes: 19 additions & 0 deletions orchestrator/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -746,3 +746,22 @@ func TestChainMismatchBeforeStorage(t *testing.T) {
require.ErrorContains(t, Serve(t.Context(), p, io.Discard), "chain ID")
require.NoDirExists(t, filepath.Dir(p.RedeemerDB))
}

func TestRedeemerHeadersFileResolutionAndRedaction(t *testing.T) {
path := filepath.Join(t.TempDir(), "redemption-headers")
require.NoError(t, os.WriteFile(path, []byte("Authorization: Bearer submission-file-secret"), 0600))
var p Params
require.NoError(t, (boa.Cmd[Params]{Params: &p, RawArgs: []string{"--redeemer-headers-file", path}}).Validate())
require.Equal(t, "Bearer submission-file-secret", http.Header(p.RedeemerHeaders).Get("Authorization"))
output, err := execute(t, "--config=", "--redeemer-url", "https://redeemer.example", "--redeemer-headers-file", path, "--print-config")
require.NoError(t, err)
require.NotContains(t, output, "submission-file-secret")
require.NotContains(t, output, path)
_, err = execute(t, "--redeemer-headers", "Authorization: Bearer literal-secret", "--print-config")
require.Error(t, err)
require.NotContains(t, err.Error(), "literal-secret")
require.NoError(t, os.Chmod(path, 0644))
p.RedeemerHeadersFile = path
p.RedeemerURL, _ = url.Parse("https://redeemer.example")
require.ErrorContains(t, p.Validate(), "owner-only")
}
10 changes: 8 additions & 2 deletions redemption/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,10 @@ type HTTPDestination struct {
endpoint string
client *http.Client
binding Binding
headers http.Header
}

func NewHTTPDestination(u *url.URL, policy destination.Policy, b Binding) (*HTTPDestination, error) {
func NewHTTPDestination(u *url.URL, policy destination.Policy, b Binding, headers ...http.Header) (*HTTPDestination, error) {
normalized, err := RedeemerURL(u)
if err != nil {
return nil, err
Expand All @@ -182,7 +183,11 @@ func NewHTTPDestination(u *url.URL, policy destination.Policy, b Binding) (*HTTP
return nil, err
}
client := &http.Client{Transport: policy.Transport(15 * time.Second), Timeout: 20 * time.Second, CheckRedirect: func(*http.Request, []*http.Request) error { return http.ErrUseLastResponse }}
return &HTTPDestination{endpoint, client, b}, nil
h := make(http.Header)
if len(headers) > 0 && headers[0] != nil {
h = headers[0].Clone()
}
return &HTTPDestination{endpoint: endpoint, client: client, binding: b, headers: h}, nil
}

func (d *HTTPDestination) Close() { d.client.CloseIdleConnections() }
Expand All @@ -196,6 +201,7 @@ func (d *HTTPDestination) Submit(ctx context.Context, t *pm.SignedTicket) error
if err != nil {
return errors.New("invalid redeemer request")
}
req.Header = d.headers.Clone()
req.Header.Set("Content-Type", "application/json")
res, err := d.client.Do(req)
if err != nil {
Expand Down
42 changes: 42 additions & 0 deletions redemption/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,3 +361,45 @@ func TestHTTPDestinationRejectsRedirectsAndBadAcknowledgments(t *testing.T) {
})
}
}

func TestDestinationSubmissionHeadersAndRedirectIsolation(t *testing.T) {
ticket, _ := winningTicket(t, 1)
var observed string
target := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
observed = r.Header.Get("Authorization")
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(202)
json.NewEncoder(w).Encode(TicketResponse{ticket.Hash()})
}))
defer target.Close()
u, _ := url.Parse(target.URL)
policy, err := destination.New("redeemer", []string{u.Host})
require.NoError(t, err)
headers := http.Header{"Authorization": []string{"Bearer submission-test"}}
d, err := NewHTTPDestination(u, policy, Binding{ChainID: "1", Controller: common.HexToAddress("0x1000")}, headers)
require.NoError(t, err)
defer d.Close()
headers.Set("Authorization", "Bearer mutated")
require.NoError(t, d.Submit(t.Context(), ticket))
require.Equal(t, "Bearer submission-test", observed)
empty, err := NewHTTPDestination(u, policy, Binding{}, http.Header(nil))
require.NoError(t, err)
defer empty.Close()
require.NoError(t, empty.Submit(t.Context(), ticket))
require.Empty(t, observed)
redirected := false
sink := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { redirected = true }))
defer sink.Close()
redirect := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, sink.URL, http.StatusTemporaryRedirect)
}))
defer redirect.Close()
u, _ = url.Parse(redirect.URL)
policy, err = destination.New("redeemer", []string{u.Host})
require.NoError(t, err)
d2, err := NewHTTPDestination(u, policy, Binding{}, http.Header{"Authorization": []string{"Bearer submission-test"}})
require.NoError(t, err)
defer d2.Close()
require.Error(t, d2.Submit(t.Context(), ticket))
require.False(t, redirected)
}
Loading