Skip to content

Commit

Permalink
server: require admin role to access node status
Browse files Browse the repository at this point in the history
Release note (security update): The node status retrieval endpoints
over HTTP (`/_status/nodes`, `/_status/nodes/<N>` and the web UI
`/#/reports/nodes`) have been updated to require the `admin` role from
the requesting user. This ensures that operational details such as
network addresses and command-line flags do not leak to unprivileged
users.
  • Loading branch information
knz committed Jun 30, 2021
1 parent 40b50c9 commit 7c25e0b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
16 changes: 15 additions & 1 deletion pkg/server/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/util/tracing/tracingpb"
"github.com/cockroachdb/errors"
gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"
"go.etcd.io/etcd/raft/v3"
raft "go.etcd.io/etcd/raft/v3"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/metadata"
Expand Down Expand Up @@ -1311,6 +1311,13 @@ func (s *statusServer) nodesHelper(
) (*serverpb.NodesResponse, int, error) {
ctx = propagateGatewayMetadata(ctx)
ctx = s.AnnotateCtx(ctx)

// The node status contains details about the command line, network
// addresses, env vars etc which are admin-only.
if _, err := s.privilegeChecker.requireAdminUser(ctx); err != nil {
return nil, 0, err
}

startKey := keys.StatusNodePrefix
endKey := startKey.PrefixEnd()

Expand Down Expand Up @@ -1383,6 +1390,13 @@ func (s *statusServer) Node(
) (*statuspb.NodeStatus, error) {
ctx = propagateGatewayMetadata(ctx)
ctx = s.AnnotateCtx(ctx)

// The node status contains details about the command line, network
// addresses, env vars etc which are admin-only.
if _, err := s.privilegeChecker.requireAdminUser(ctx); err != nil {
return nil, err
}

nodeID, _, err := s.parseNodeID(req.NodeId)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, err.Error())
Expand Down
17 changes: 15 additions & 2 deletions pkg/server/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -786,8 +786,14 @@ func TestNodeStatusResponse(t *testing.T) {
s := startServer(t)
defer s.Stopper().Stop(context.Background())

// First fetch all the node statuses.
wrapper := serverpb.NodesResponse{}

// Check that the node statuses cannot be accessed via a non-admin account.
if err := getStatusJSONProtoWithAdminOption(s, "nodes", &wrapper, false /* isAdmin */); !testutils.IsError(err, "status: 403") {
t.Fatalf("expected privilege error, got %v", err)
}

// Now fetch all the node statuses as admin.
if err := getStatusJSONProto(s, "nodes", &wrapper); err != nil {
t.Fatal(err)
}
Expand All @@ -804,7 +810,14 @@ func TestNodeStatusResponse(t *testing.T) {
// ids only.
for _, oldNodeStatus := range nodeStatuses {
nodeStatus := statuspb.NodeStatus{}
if err := getStatusJSONProto(s, "nodes/"+oldNodeStatus.Desc.NodeID.String(), &nodeStatus); err != nil {
nodeURL := "nodes/" + oldNodeStatus.Desc.NodeID.String()
// Check that the node statuses cannot be accessed via a non-admin account.
if err := getStatusJSONProtoWithAdminOption(s, nodeURL, &nodeStatus, false /* isAdmin */); !testutils.IsError(err, "status: 403") {
t.Fatalf("expected privilege error, got %v", err)
}

// Now access that node's status.
if err := getStatusJSONProto(s, nodeURL, &nodeStatus); err != nil {
t.Fatal(err)
}
if !s.node.Descriptor.Equal(&nodeStatus.Desc) {
Expand Down

0 comments on commit 7c25e0b

Please sign in to comment.