sourcegraph/internal/debugserver
Robert Lin 704b36a143
feat/enterprise-portal: ConnectRPC layer for {Get/List}CodyGatewayAccess (#62771)
This PR exposes the data layer implemented in https://github.com/sourcegraph/sourcegraph/pull/62706 via the Enterprise Portal API. We register the services proposed in #62263 and also set up tooling like gRPC UI locally for DX.

Auth is via SAMS M2M; https://github.com/sourcegraph/sourcegraph-accounts-sdk-go/pull/28 and https://github.com/sourcegraph/sourcegraph-accounts/pull/227 rolls out the new scopes, and https://github.com/sourcegraph/managed-services/pull/1474 adds credentials for the enterprise-portal-dev deployment.

Closes CORE-112

## Test plan

https://github.com/sourcegraph/sourcegraph/pull/62706 has extensive testing of the data layer, and this PR expands on it a little bit. I tested the RPC layer by hand:

Create SAMS client for Enterprise Portal Dev in **accounts.sgdev.org**:

```sh
curl -s -X POST \
        -H "Authorization: Bearer $MANAGEMENT_SECRET" \
        https://accounts.sgdev.org/api/management/v1/identity-provider/clients \
--data '{"name": "enterprise-portal-dev", "scopes": [], "redirect_uris": ["https://enterprise-portal.sgdev.org"]}' | jq
```

Configure `sg.config.overwrite.yaml`

```yaml
  enterprise-portal:
    env:
      SRC_LOG_LEVEL: debug
      # sams-dev
      SAMS_URL: https://accounts.sgdev.org
      ENTERPRISE_PORTAL_SAMS_CLIENT_ID: "sams_cid_..."
      ENTERPRISE_PORTAL_SAMS_CLIENT_SECRET: "sams_cs_..."
```

Create a test client (later, we will do the same thing for Cody Gateway), also in **accounts.sgdev.org**:

```sh
curl -s -X POST \
        -H "Authorization: Bearer $MANAGEMENT_SECRET" \
        https://accounts.sgdev.org/api/management/v1/identity-provider/clients \
--data '{"name": "enterprise-portal-dev-reader", "scopes": ["enterprise_portal::codyaccess::read", "enterprise_portal::subscription::read"], "redirect_uris": ["https://enterprise-portal.sgdev.org"]}' | jq
```

Then:

```
sg run enterprise-portal
```

Navigate to the locally-enabled gRPC debug UI at http://localhost:6081/debug/grcpui, using https://github.com/sourcegraph/sourcegraph/pull/62883 to get an access token from our test client to add in the request metadata:

```sh
sg sams create-client-token -s 'enterprise_portal::codyaccess::read'
```

I'm using some local subscriptions I've made previously in `sg start dotcom`:

![image](https://github.com/sourcegraph/sourcegraph/assets/23356519/a55c6f0d-b0ae-4e68-8e4c-ccb6e2cc442d)

![image](https://github.com/sourcegraph/sourcegraph/assets/23356519/19d18104-1051-4a82-abe0-58010dd13a27)

Without a valid authorization header:

![image](https://github.com/sourcegraph/sourcegraph/assets/23356519/c9cf4c89-9902-48f8-ac41-daf9a63ca789)

Verified a lookup using the returned access tokens also works

---------

Co-authored-by: Jean-Hadrien Chabran <jh@chabran.fr>
Co-authored-by: Joe Chen <joe@sourcegraph.com>
2024-05-27 13:39:57 -07:00
..
BUILD.bazel bazel: transcribe test ownership to bazel tags (#62664) 2024-05-16 15:51:16 +01:00
CODENOTIFY all: add keegancsmith to CODENOTIFY for many pkgs (#14241) 2020-09-29 11:03:53 +02:00
debug.go lib/background: upgrade Routine interface with context and errors (#62136) 2024-05-24 10:04:55 -04:00
expvar.go tidy: convert Fprintf to Fprintln when possible (#7174) 2019-12-12 12:46:02 -07:00
grpcui.go feat/enterprise-portal: ConnectRPC layer for {Get/List}CodyGatewayAccess (#62771) 2024-05-27 13:39:57 -07:00
metadata.go monitoring: version metric, annotations on versions and alerts (#17198) 2021-01-13 00:14:18 +08:00
ready.go debugserver: Add /healthz and /ready endpoints (#19846) 2021-04-08 20:21:29 +00:00