Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: Add API example to documentation #11

Merged
merged 1 commit into from
Mar 17, 2023
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
26 changes: 1 addition & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,7 @@ Proxy that provides access to the VNC console of a Kubevirt VM.
It can generate time limited tokens that are then used to access VNC.

## API

### Generate a token
A temporary token can be generated using:
```
GET /api/v1alpha1/${VMI_NAMESPACE}/${VMI_NAME}/token
```
Where `${VMI_NAMESPACE}` and `${VMI_NAME}` are the namespace
and name of a running VMI.

Parameters:
- `duration` - Duration while the token is valid

Headers:
- `Authorization` - Contains Bearer token that is used to check
RBAC permissions to access `/vnc` subresource on a VMI

### Access VNC
VNC can be accessed using websocket on this endpoint:
```
/api/v1alpha1/${VMI_NAMESPACE}/${VMI_NAME}/vnc
```

This subprotocol is used for authorization:
- `base64url.bearer.authorization.k8s.io.${TOKEN}` - The `${TOKEN}`
is a token generated by the above endpoint.
See the [API documentation](docs/api.md).

## Exposing the service

Expand Down
52 changes: 52 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# API

The commands in this document use environment variable `PROXY_URL`,
which should be set to the URL where the `vm-console-proxy` service is
exposed to the outside of the cluster.

## Generate a token

A temporary token can be generated using:
```
GET /api/v1alpha1/${VMI_NAMESPACE}/${VMI_NAME}/token
```
Where `${VMI_NAMESPACE}` and `${VMI_NAME}` are the namespace
and name of a running VMI.

#### Parameters
- `duration` - Duration while the token is valid

#### Headers
- `Authorization` - Contains Bearer token that is used to check
RBAC permissions to access `/vnc` subresource on a VMI

#### Result
Result is a JSON object containing the token:
```json
{ "token": "eyJhb..." }
```

### Example
```bash
curl --header "Authorization: Bearer ${KUBERNETES_USER_TOKEN}" \
"https://${PROXY_URL}/api/v1alpha1/${VMI_NAMESPACE}/${VMI_NAME}/token?duration=${DURATION}"
```

The `KUBERNETES_USER_TOKEN` variable is a bearer token used to authenticate with
kubernetes API. It can be obtained using:
```bash
KUBERNETES_USER_TOKEN=$(oc whoami -t)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add an example on how to acquire a token with kubectl too?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure there is a simple command to do that using kubectl.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, I'd love to see this also run on plain Kubernetes.

```

## Accessing VNC
VNC can be accessed using websocket on this endpoint:
```
/api/v1alpha1/${VMI_NAMESPACE}/${VMI_NAME}/vnc
```

#### Subprotocol
akrejcir marked this conversation as resolved.
Show resolved Hide resolved
- `base64url.bearer.authorization.k8s.io.${TOKEN}` - Is used for authorization. The `TOKEN`
variable is a token generated by the `/token` endpoint.

### Example
The `example-client` subdirectory shows how to access this endpoint using the [noVNC](https://novnc.com/info.html) JavaScript library.