Skip to content

Commit cdbcd47

Browse files
authored
Admin: stub out override and pausing methods for dry-run (#8579)
Dry run stubs for the SA's override and pausing methods were not added when this functionality was added to the admin tool. This means that attempts to run these subcommands in dry-run mode result in nil pointer exceptions when it tries to call unimplemented methods on the dryRunSAC. Fixes #8577
1 parent 2acc85b commit cdbcd47

3 files changed

Lines changed: 53 additions & 8 deletions

File tree

cmd/admin/admin.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"fmt"
77

88
"github.com/jmhodges/clock"
9+
"google.golang.org/grpc"
10+
"google.golang.org/protobuf/types/known/emptypb"
911

1012
"github.com/letsencrypt/boulder/cmd"
1113
"github.com/letsencrypt/boulder/features"
@@ -18,14 +20,29 @@ import (
1820
// admin holds all of the external connections necessary to perform admin
1921
// actions on a boulder deployment.
2022
type admin struct {
21-
rac rapb.RegistrationAuthorityClient
22-
sac sapb.StorageAuthorityClient
23+
rac adminRAClient
24+
sac adminSAClient
2325
saroc sapb.StorageAuthorityReadOnlyClient
2426

2527
clk clock.Clock
2628
log blog.Logger
2729
}
2830

31+
// adminRAClient defines the subset of RA methods that the admin tool relies on.
32+
type adminRAClient interface {
33+
AdministrativelyRevokeCertificate(context.Context, *rapb.AdministrativelyRevokeCertificateRequest, ...grpc.CallOption) (*emptypb.Empty, error)
34+
}
35+
36+
// adminSAClient defines the subset of SA methods that the admin tool relies on.
37+
type adminSAClient interface {
38+
AddBlockedKey(context.Context, *sapb.AddBlockedKeyRequest, ...grpc.CallOption) (*emptypb.Empty, error)
39+
AddRateLimitOverride(context.Context, *sapb.AddRateLimitOverrideRequest, ...grpc.CallOption) (*sapb.AddRateLimitOverrideResponse, error)
40+
DisableRateLimitOverride(context.Context, *sapb.DisableRateLimitOverrideRequest, ...grpc.CallOption) (*emptypb.Empty, error)
41+
EnableRateLimitOverride(context.Context, *sapb.EnableRateLimitOverrideRequest, ...grpc.CallOption) (*emptypb.Empty, error)
42+
PauseIdentifiers(context.Context, *sapb.PauseRequest, ...grpc.CallOption) (*sapb.PauseIdentifiersResponse, error)
43+
UnpauseAccount(context.Context, *sapb.RegistrationID, ...grpc.CallOption) (*sapb.Count, error)
44+
}
45+
2946
// newAdmin constructs a new admin object on the heap and returns a pointer to
3047
// it.
3148
func newAdmin(configFile string, dryRun bool) (*admin, error) {
@@ -51,7 +68,7 @@ func newAdmin(configFile string, dryRun bool) (*admin, error) {
5168
return nil, fmt.Errorf("loading TLS config: %w", err)
5269
}
5370

54-
var rac rapb.RegistrationAuthorityClient = dryRunRAC{log: logger}
71+
var rac adminRAClient = dryRunRAC{log: logger}
5572
if !dryRun {
5673
raConn, err := bgrpc.ClientSetup(c.Admin.RAService, tlsConfig, scope, clk)
5774
if err != nil {
@@ -66,7 +83,7 @@ func newAdmin(configFile string, dryRun bool) (*admin, error) {
6683
}
6784
saroc := sapb.NewStorageAuthorityReadOnlyClient(saConn)
6885

69-
var sac sapb.StorageAuthorityClient = dryRunSAC{log: logger}
86+
var sac adminSAClient = dryRunSAC{log: logger}
7087
if !dryRun {
7188
sac = sapb.NewStorageAuthorityClient(saConn)
7289
}

cmd/admin/dryrun.go

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ import (
1313
)
1414

1515
type dryRunRAC struct {
16-
rapb.RegistrationAuthorityClient
1716
log blog.Logger
1817
}
1918

19+
var _ adminRAClient = (*dryRunRAC)(nil)
20+
2021
func (d dryRunRAC) AdministrativelyRevokeCertificate(_ context.Context, req *rapb.AdministrativelyRevokeCertificateRequest, _ ...grpc.CallOption) (*emptypb.Empty, error) {
2122
b, err := prototext.Marshal(req)
2223
if err != nil {
@@ -27,11 +28,37 @@ func (d dryRunRAC) AdministrativelyRevokeCertificate(_ context.Context, req *rap
2728
}
2829

2930
type dryRunSAC struct {
30-
sapb.StorageAuthorityClient
3131
log blog.Logger
3232
}
3333

34+
var _ adminSAClient = (*dryRunSAC)(nil)
35+
3436
func (d dryRunSAC) AddBlockedKey(_ context.Context, req *sapb.AddBlockedKeyRequest, _ ...grpc.CallOption) (*emptypb.Empty, error) {
3537
d.log.Infof("dry-run: Block SPKI hash %x by %s %s", req.KeyHash, req.Comment, req.Source)
3638
return &emptypb.Empty{}, nil
3739
}
40+
41+
func (d dryRunSAC) AddRateLimitOverride(_ context.Context, req *sapb.AddRateLimitOverrideRequest, _ ...grpc.CallOption) (*sapb.AddRateLimitOverrideResponse, error) {
42+
d.log.Infof("dry-run: Add override for %q (%s)", req.Override.BucketKey, req.Override.Comment)
43+
return &sapb.AddRateLimitOverrideResponse{Inserted: true, Enabled: true}, nil
44+
}
45+
46+
func (d dryRunSAC) DisableRateLimitOverride(_ context.Context, req *sapb.DisableRateLimitOverrideRequest, _ ...grpc.CallOption) (*emptypb.Empty, error) {
47+
d.log.Infof("dry-run: Disable override for %q", req.BucketKey)
48+
return &emptypb.Empty{}, nil
49+
}
50+
51+
func (d dryRunSAC) EnableRateLimitOverride(_ context.Context, req *sapb.EnableRateLimitOverrideRequest, _ ...grpc.CallOption) (*emptypb.Empty, error) {
52+
d.log.Infof("dry-run: Enable override for %q", req.BucketKey)
53+
return &emptypb.Empty{}, nil
54+
}
55+
56+
func (d dryRunSAC) PauseIdentifiers(_ context.Context, req *sapb.PauseRequest, _ ...grpc.CallOption) (*sapb.PauseIdentifiersResponse, error) {
57+
d.log.Infof("dry-run: Pause identifiers %#v for account %d", req.Identifiers, req.RegistrationID)
58+
return &sapb.PauseIdentifiersResponse{Paused: int64(len(req.Identifiers))}, nil
59+
}
60+
61+
func (d dryRunSAC) UnpauseAccount(_ context.Context, req *sapb.RegistrationID, _ ...grpc.CallOption) (*sapb.Count, error) {
62+
d.log.Infof("dry-run: Unpause account %d", req.Id)
63+
return &sapb.Count{Count: 1}, nil
64+
}

cmd/admin/overrides_dump.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ import (
77
"fmt"
88
"io"
99

10+
"google.golang.org/protobuf/types/known/emptypb"
11+
1012
"github.com/letsencrypt/boulder/config"
1113
"github.com/letsencrypt/boulder/ratelimits"
12-
"google.golang.org/protobuf/types/known/emptypb"
1314
)
1415

1516
type subcommandDumpEnabledOverrides struct {
@@ -29,7 +30,7 @@ func (c *subcommandDumpEnabledOverrides) Run(ctx context.Context, a *admin) erro
2930
return errors.New("--file is required")
3031
}
3132

32-
stream, err := a.sac.GetEnabledRateLimitOverrides(ctx, &emptypb.Empty{})
33+
stream, err := a.saroc.GetEnabledRateLimitOverrides(ctx, &emptypb.Empty{})
3334
if err != nil {
3435
return fmt.Errorf("fetching enabled overrides: %w", err)
3536
}

0 commit comments

Comments
 (0)