Skip to content

Commit b2a04c5

Browse files
Merge pull request #32 from pluralsh/sebastian/prod-3068-add-ability-to-log-api-calls-from-kas-back-to-the-console
feat: add audit logging to kas
2 parents 7dc440c + c560c15 commit b2a04c5

20 files changed

+179
-158
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# GitLab Agent for Kubernetes
1+
# Plural Agent for Kubernetes
22

3-
GitLab Agent for Kubernetes is an active in-cluster component for solving any GitLab<->Kubernetes integration tasks.
3+
Plural Agent for Kubernetes is an active in-cluster component for solving any Plural<->Kubernetes integration tasks.
44

5-
It's implemented as two communicating pieces - GitLab Agent (`agentk`) that is running in the cluster and GitLab Agent Server (`gitlab-kas`) that is running on the GitLab side. Please see the [architecture](doc/architecture.md) document and other documents in the [doc](doc) directory for more information. [User-facing documentation](https://docs.gitlab.com/ee/user/clusters/agent/) is also available.
5+
It's implemented as two communicating pieces - Plural Agent (`agentk`) that is running in the cluster and Plural Agent Server (`gitlab-kas`) that is running on the Plural side. Please see the [architecture](doc/architecture.md) document and other documents in the [doc](doc) directory for more information. [User-facing documentation](https://docs.gitlab.com/ee/user/clusters/agent/) is also available.
66

77
## Contributing
88

cmd/kas/kasapp/app.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func NewCommand() *cobra.Command {
8181
a := App{}
8282
c := &cobra.Command{
8383
Use: "kas",
84-
Short: "GitLab Kubernetes Agent Server",
84+
Short: "Plural Kubernetes Agent Server",
8585
Args: cobra.NoArgs,
8686
RunE: func(cmd *cobra.Command, args []string) error {
8787
return a.Run(cmd.Context())

cmd/kas/kasapp/configured_app.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ func (a *ConfiguredApp) Run(ctx context.Context) (retErr error) {
177177
return fmt.Errorf("agent server: %w", err)
178178
}
179179

180-
// Server for handling external requests e.g. from GitLab
180+
// Server for handling external requests e.g. from Plural
181181
apiSrv, err := newApiServer(a.Log, a.Configuration, tp, mp, p, ssh, rpcApiFactory, probeRegistry, // nolint: contextcheck
182182
streamProm, unaryProm, grpcServerErrorReporter)
183183
if err != nil {
@@ -597,7 +597,7 @@ func gitlabBuildInfoGauge(m otelmetric.Meter) error {
597597
// Only allocate the option once
598598
attributes := otelmetric.WithAttributeSet(attribute.NewSet(kasVersionAttr.String(cmd.Version), kasBuiltAttr.String(cmd.BuildTime)))
599599
_, err := m.Int64ObservableGauge(gitlabBuildInfoGaugeMetricName,
600-
otelmetric.WithDescription("Current build info for this GitLab Service"),
600+
otelmetric.WithDescription("Current build info for this Plural Service"),
601601
otelmetric.WithInt64Callback(func(ctx context.Context, observer otelmetric.Int64Observer) error {
602602
observer.Observe(1, attributes)
603603
return nil

doc/architecture.md

+20-20
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
## Issues the agent is trying to address
44

5-
- Integrate a cluster, located behind a firewall or NAT, with GitLab. To
6-
learn more, read [issue #212810, Invert the model GitLab.com uses for Kubernetes integration by leveraging long lived reverse tunnels](https://gitlab.com/gitlab-org/gitlab/-/issues/212810).
5+
- Integrate a cluster, located behind a firewall or NAT, with Plural. To
6+
learn more, read [issue #212810, Invert the model Plural.com uses for Kubernetes integration by leveraging long lived reverse tunnels](https://gitlab.com/gitlab-org/gitlab/-/issues/212810).
77
- Access API endpoints in a cluster in real time. For an example use case, read
88
[issue #218220, Allow Prometheus in K8s cluster to be installed manually](https://gitlab.com/gitlab-org/gitlab/-/issues/218220#note_348729266).
99
- Enable real-time features by pushing information about events happening in a cluster.
@@ -22,55 +22,55 @@
2222

2323
## High-level architecture
2424

25-
The GitLab Agent and the GitLab Agent Server use
25+
The Plural Agent and the Plural Agent Server use
2626
[bidirectional streaming](https://grpc.io/docs/what-is-grpc/core-concepts/#bidirectional-streaming-rpc)
27-
to allow the connection acceptor (the gRPC server, GitLab Agent Server) to
27+
to allow the connection acceptor (the gRPC server, Plural Agent Server) to
2828
act as a client. The connection acceptor sends requests as gRPC replies. The client-server
2929
relationship is inverted because the connection must be initiated from inside the
3030
Kubernetes cluster to bypass any firewall or NAT the cluster may be located behind.
3131
To learn more about this inversion, read
3232
[issue #212810](https://gitlab.com/gitlab-org/gitlab/-/issues/212810).
3333

34-
This diagram describes how GitLab (`GitLab RoR`), the GitLab Agent (`agentk`), and the GitLab Agent Server (`kas`) work together.
34+
This diagram describes how Plural (`Plural RoR`), the Plural Agent (`agentk`), and the Plural Agent Server (`kas`) work together.
3535

3636
```mermaid
3737
graph TB
3838
agentk -- gRPC bidirectional streaming --> kas
3939
40-
subgraph "GitLab"
40+
subgraph "Plural"
4141
kas[kas]
42-
GitLabRoR[GitLab RoR] -- gRPC --> kas
42+
PluralRoR[Plural RoR] -- gRPC --> kas
4343
kas -- gRPC --> Gitaly[Gitaly]
44-
kas -- REST API --> GitLabRoR
44+
kas -- REST API --> PluralRoR
4545
end
4646
4747
subgraph "Kubernetes cluster"
4848
agentk[agentk]
4949
end
5050
```
5151

52-
- `GitLab RoR` is the main GitLab application. It uses gRPC to talk to `kas`.
53-
- `agentk` is the GitLab Agent. It keeps a connection established to a
52+
- `Plural RoR` is the main Plural application. It uses gRPC to talk to `kas`.
53+
- `agentk` is the Plural Agent. It keeps a connection established to a
5454
`kas` instance, waiting for requests to process. It may also actively send information
5555
about things happening in the cluster.
56-
- `kas` is the GitLab Agent Server, and is responsible for:
56+
- `kas` is the Plural Agent Server, and is responsible for:
5757
- Accepting requests from `agentk`.
58-
- [Authentication of requests](https://gitlab.com/gitlab-org/cluster-integration/gitlab-agent/-/blob/master/doc/identity_and_auth.md) from `agentk` by querying `GitLab RoR`.
58+
- [Authentication of requests](https://gitlab.com/gitlab-org/cluster-integration/gitlab-agent/-/blob/master/doc/identity_and_auth.md) from `agentk` by querying `Plural RoR`.
5959
- Fetching agent's configuration from a corresponding Git repository by querying Gitaly.
60-
- Matching incoming requests from `GitLab RoR` with existing connections from
60+
- Matching incoming requests from `Plural RoR` with existing connections from
6161
the right `agentk`, forwarding requests to it and forwarding responses back.
6262
- (Optional) Sending notifications through ActionCable for events received from `agentk`.
6363
- Polling manifest repositories for [GitOps support](https://gitlab.com/gitlab-org/cluster-integration/gitlab-agent/-/blob/master/doc/gitops.md) by communicating with Gitaly.
6464

6565
<i class="fa fa-youtube-play youtube" aria-hidden="true"></i>
6666
To learn more about how the repository is structured, see
67-
[GitLab Agent repository overview](https://www.youtube.com/watch?v=j8CyaCWroUY).
67+
[Plural Agent repository overview](https://www.youtube.com/watch?v=j8CyaCWroUY).
6868

6969
## Guiding principles
7070

71-
GitLab prefers to add logic into `kas` rather than `agentk`. `agentk` should be kept
72-
streamlined and small to minimize the need for upgrades. On GitLab.com, `kas` is
73-
managed by GitLab, so upgrades and features can be added without requiring you
71+
Plural prefers to add logic into `kas` rather than `agentk`. `agentk` should be kept
72+
streamlined and small to minimize the need for upgrades. On Plural.com, `kas` is
73+
managed by Plural, so upgrades and features can be added without requiring you
7474
to upgrade `agentk` in your clusters.
7575

7676
`agentk` can't be viewed as a dumb reverse proxy because features are planned to be built
@@ -80,11 +80,11 @@ to upgrade `agentk` in your clusters.
8080

8181
- **Q**: Why do we need long-running connections? Cannot we just ask users to punch a hole in their firewall?
8282

83-
**A**: Even if it was always possible, having an agent running in the cluster enables us to build more features, not just connecting such clusters to GitLab.
83+
**A**: Even if it was always possible, having an agent running in the cluster enables us to build more features, not just connecting such clusters to Plural.
8484

8585
- **Q**: Why do we need long-running connections? Can we use polling instead?
8686

87-
**A**: Polling will not allow for real-time access to the in-cluster APIs. For example, our metrics integration queries Prometheus API to get the data for dashboards. I.e. the request comes from GitLab, not from the Kubernetes side.
87+
**A**: Polling will not allow for real-time access to the in-cluster APIs. For example, our metrics integration queries Prometheus API to get the data for dashboards. I.e. the request comes from Plural, not from the Kubernetes side.
8888

8989
- **Q**: Can we push data about things happening in the cluster using REST API instead of using streaming?
9090

@@ -100,7 +100,7 @@ to upgrade `agentk` in your clusters.
100100

101101
**A**: There are several reasons:
102102

103-
- Allows the GitLab instance operator to configure polling frequency and any other relevant parameters. Makes it harder for the user to misuse/abuse the system.
103+
- Allows the Plural instance operator to configure polling frequency and any other relevant parameters. Makes it harder for the user to misuse/abuse the system.
104104

105105
- Fewer knobs for the user to tweak means more straightforward configuration experience.
106106

doc/developing.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77
Most up-to-date video describing how this repository is
88
structured:
99

10-
[![GitLab Agent repository overview - It's time to Go! Episode 5](https://img.youtube.com/vi/Mh7PG4_cBxI/0.jpg)](https://www.youtube.com/watch?v=Mh7PG4_cBxI "GitLab Agent repository overview")
10+
[![Plural Agent repository overview - It's time to Go! Episode 5](https://img.youtube.com/vi/Mh7PG4_cBxI/0.jpg)](https://www.youtube.com/watch?v=Mh7PG4_cBxI "Plural Agent repository overview")
1111

1212
### Past recordings
1313

1414
#### 2021-11-20
1515

16-
[![GitLab Agent repository overview](http://img.youtube.com/vi/j8CyaCWroUY/1.jpg)](http://www.youtube.com/watch?v=j8CyaCWroUY "GitLab Agent repository overview")
16+
[![Plural Agent repository overview](http://img.youtube.com/vi/j8CyaCWroUY/1.jpg)](http://www.youtube.com/watch?v=j8CyaCWroUY "Plural Agent repository overview")
1717

1818
## Running kas and agentk locally
1919

20-
[![GitLab Agent development environment setup](https://img.youtube.com/vi/UWptMO-Amtc/0.jpg)](https://www.youtube.com/watch?v=UWptMO-Amtc "GitLab Agent development environment setup")
20+
[![Plural Agent development environment setup](https://img.youtube.com/vi/UWptMO-Amtc/0.jpg)](https://www.youtube.com/watch?v=UWptMO-Amtc "Plural Agent development environment setup")
2121

2222
You can run `kas` and `agentk` locally to test the Agent yourself.
2323

@@ -36,7 +36,7 @@ You can run `kas` and `agentk` locally to test the Agent yourself.
3636
1. Start the binaries with the following commands:
3737

3838
```shell
39-
# Start GitLab but stop GDK's version of kas.
39+
# Start Plural but stop GDK's version of kas.
4040
gdk start && gdk stop gitlab-k8s-agent
4141

4242
# Let kas know it's own private API url
@@ -148,8 +148,8 @@ For `agentk`:
148148
It's optional, but consider also specifying `--context=<desired context>` command line argument to not depend on the currently selected context.
149149
## kas QA tests
150150

151-
This section describes how to run kas tests against different GitLab environments based on the
152-
[GitLab QA orchestrator](https://gitlab.com/gitlab-org/gitlab-qa).
151+
This section describes how to run kas tests against different Plural environments based on the
152+
[Plural QA orchestrator](https://gitlab.com/gitlab-org/gitlab-qa).
153153

154154
### Status
155155

@@ -240,7 +240,7 @@ startup --output_user_root=/Volumes/ramdisk
240240

241241
## Ruby gRPC interface
242242

243-
In `pkg/ruby` we generate Ruby gRPC types intended to be used by GitLab to interact with KAS.
243+
In `pkg/ruby` we generate Ruby gRPC types intended to be used by Plural to interact with KAS.
244244
The following sections outline how to build a test that generated Ruby code in the context of GDK.
245245

246246
### Build
@@ -256,7 +256,7 @@ To use this locally built gem in GDK do:
256256
1. Run `bundle install`
257257
1. Restart GDK with `gdk restart`
258258

259-
After that you can either implement and test changes like with any other GitLab work or
259+
After that you can either implement and test changes like with any other Plural work or
260260
use `gdk rails console` to exploratory test, e.g.:
261261

262262
```irb

doc/identity_and_auth.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Identity and authentication
22

33
This page uses the word `agent` to describe the concept of the
4-
GitLab Agent for Kubernetes. The program that implements the concept is called `agentk`.
4+
Plural Agent for Kubernetes. The program that implements the concept is called `agentk`.
55
Read the
66
[architecture page](https://gitlab.com/gitlab-org/cluster-integration/gitlab-agent/-/blob/master/doc/architecture.md)
77
for more information.
88

99
## Agent identity and name
1010

11-
In a GitLab installation, each agent must have a unique, immutable name. This
11+
In a Plural installation, each agent must have a unique, immutable name. This
1212
name must be unique in the project the agent is attached to, and this name must
1313
follow the [DNS label standard from RFC 1123](https://tools.ietf.org/html/rfc1123).
1414
The name must:
@@ -45,12 +45,12 @@ and minimize the permissions each particular agent needs.
4545

4646
## Agent authentication
4747

48-
When adding a new agent, GitLab provides the user with a bearer access token. The
49-
agent uses this token to authenticate with GitLab. This token is a random string
48+
When adding a new agent, Plural provides the user with a bearer access token. The
49+
agent uses this token to authenticate with Plural. This token is a random string
5050
and does not encode any information in it, but it is secret and must
5151
be treated with care. Store it as a `Secret` in Kubernetes.
5252

53-
Each agent can have 0 or more tokens in a GitLab database. Having several valid
53+
Each agent can have 0 or more tokens in a Plural database. Having several valid
5454
tokens helps you rotate tokens without needing to re-register an agent. Each token
5555
record in the database has the following fields:
5656

@@ -72,8 +72,8 @@ Tokens are immutable, and only the following fields can be updated:
7272
- Revocation time. Set to the current time when revocation flag is set, but immutable after that.
7373
- Comments field. Can be updated any number of times, including after the token has been revoked.
7474

75-
The agent sends its token, along with each request, to GitLab to authenticate itself.
76-
For each request, GitLab checks the token's validity:
75+
The agent sends its token, along with each request, to Plural to authenticate itself.
76+
For each request, Plural checks the token's validity:
7777

7878
- Does the token exist in the database?
7979
- Has the token been revoked?
@@ -82,7 +82,7 @@ This information may be cached for some time to reduce load on the database.
8282

8383
## Agent authorization
8484

85-
GitLab provides the following information in its response for a given Agent access token:
85+
Plural provides the following information in its response for a given Agent access token:
8686

8787
- Agent configuration Git repository. (The agent doesn't support per-folder authorization.)
8888
- Agent name.

doc/kas_request_routing.md

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
# Routing `kas` requests in the Agent
22

33
This document describes how `kas` routes requests to concrete `agentk` instances.
4-
GitLab must talk to GitLab Agent Server (`kas`) to:
4+
Plural must talk to Plural Agent Server (`kas`) to:
55

66
- Get information about connected agents. [Read more](https://gitlab.com/gitlab-org/gitlab/-/issues/249560).
77
- Interact with agents. [Read more](https://gitlab.com/gitlab-org/gitlab/-/issues/230571).
88
- Interact with Kubernetes clusters. [Read more](https://gitlab.com/gitlab-org/gitlab/-/issues/240918).
99

1010
Each agent connects to an instance of `kas` and keeps an open connection. When
11-
GitLab must talk to a particular agent, a `kas` instance connected to this agent must
11+
Plural must talk to a particular agent, a `kas` instance connected to this agent must
1212
be found, and the request routed to it.
1313

1414
## Walk Through
1515

1616
[Mikhail (`@ash2k`)](https://gitlab.com/ash2k) and [Timo (`@timofurrer`)](https://gitlab.com/timofurrer) recorded
1717
a video where they walk through the most important parts of the KAS <-> Agentk routing and tunneling.
1818

19-
[![GitLab Agent for K8s: Deep Dive into KAS and Agentk connection handling and tunneling requests](https://img.youtube.com/vi/6U6A5tGCszE/0.jpg)](https://youtu.be/6U6A5tGCszE "GitLab Agent for K8s: Deep Dive into KAS and Agentk connection handling and tunneling requests")
19+
[![Plural Agent for K8s: Deep Dive into KAS and Agentk connection handling and tunneling requests](https://img.youtube.com/vi/6U6A5tGCszE/0.jpg)](https://youtu.be/6U6A5tGCszE "Plural Agent for K8s: Deep Dive into KAS and Agentk connection handling and tunneling requests")
2020

2121
## System design
2222

@@ -43,10 +43,10 @@ flowchart LR
4343
kas3["kas 3"]
4444
end
4545
46-
GitLab["GitLab Rails"]
46+
Plural["Plural Rails"]
4747
Redis
4848
49-
GitLab -- "gRPC to any kas" --> kas
49+
Plural -- "gRPC to any kas" --> kas
5050
kas1 -- register connected agents --> Redis
5151
kas2 -- register connected agents --> Redis
5252
kas1 -- lookup agent --> Redis
@@ -61,7 +61,7 @@ For this architecture, this diagram shows a request to `agentk 3, Pod1` for the
6161

6262
```mermaid
6363
sequenceDiagram
64-
GitLab->>+kas1: Get list of running<br />Pods from agentk<br />with agent_id=3
64+
Plural->>+kas1: Get list of running<br />Pods from agentk<br />with agent_id=3
6565
Note right of kas1: kas1 checks for<br />agent connected with agent_id=3.<br />It does not.<br />Queries Redis
6666
kas1->>+Redis: Get list of connected agents<br />with agent_id=3
6767
Redis-->-kas1: List of connected agents<br />with agent_id=3
@@ -70,7 +70,7 @@ sequenceDiagram
7070
kas2->>+agentk 3 Pod1: Get list of Pods
7171
agentk 3 Pod1->>-kas2: Get list of Pods
7272
kas2-->>-kas1: List of running Pods<br />from agentk 3, Pod1
73-
kas1-->>-GitLab: List of running Pods<br />from agentk with agent_id=3
73+
kas1-->>-Plural: List of running Pods<br />from agentk with agent_id=3
7474
```
7575

7676
Each `kas` instance tracks the agents connected to it in Redis. For each agent, it
@@ -99,22 +99,22 @@ When `kas` must atomically update multiple data structures in Redis, it uses
9999
Grouped data items must have the same expiration time.
100100

101101
In addition to the existing `agentk -> kas` gRPC endpoint, `kas` exposes two new,
102-
separate gRPC endpoints for GitLab and for `kas -> kas` requests. Each endpoint
102+
separate gRPC endpoints for Plural and for `kas -> kas` requests. Each endpoint
103103
is a separate network listener, making it easier to control network access to endpoints
104104
and allowing separate configuration for each endpoint.
105105

106106
Databases, like PostgreSQL, aren't used because the data is transient, with no need
107107
to reliably persist it.
108108

109-
### `GitLab : kas` external endpoint
109+
### `Plural : kas` external endpoint
110110

111-
GitLab authenticates with `kas` using JWT and the same shared secret used by the
112-
`kas -> GitLab` communication. The JWT issuer should be `gitlab` and the audience
111+
Plural authenticates with `kas` using JWT and the same shared secret used by the
112+
`kas -> Plural` communication. The JWT issuer should be `gitlab` and the audience
113113
should be `gitlab-kas`.
114114

115115
When accessed through this endpoint, `kas` plays the role of request router.
116116

117-
If a request from GitLab comes but no connected agent can handle it, `kas` blocks
117+
If a request from Plural comes but no connected agent can handle it, `kas` blocks
118118
and waits for a suitable agent to connect to it or to another `kas` instance. It
119119
stops waiting when the client disconnects, or when some long timeout happens, such
120120
as client timeout. `kas` is notified of new agent connections through a
@@ -139,7 +139,7 @@ how a request is routed, rather than distributing the decision across several `k
139139
This section explains how the `kas`-> `kas` -> `agentk` gRPC request routing is implemented.
140140

141141
For a video overview of how some of the blocks map to code, see
142-
[GitLab Agent reverse gRPC tunnel architecture and code overview
142+
[Plural Agent reverse gRPC tunnel architecture and code overview
143143
](https://www.youtube.com/watch?v=9pnQF76hyZc).
144144

145145
#### High level schema

0 commit comments

Comments
 (0)