Skip to content

Commit

Permalink
Create oAuth client for frontend service (#87)
Browse files Browse the repository at this point in the history
This is work on #27, just the part that sets up and provides the details
to Kubernetes for the oAuth authentication tokens.

This PR:

* Generates an internal oAuth brand and client token
* Provides instructions on how to make it external
* Generates a `ConfigMap` with the env data that will need to be passed
  to the eventual `frontend` Pod container.
* Deploy said ConfigMap to the Services cluster.

I also rename "frontend-api" to "frontend", since the "api" part seemed
redundant.

Next should be Cloud Build the image and Deploy it as a `Deployment` and
`Service`.
  • Loading branch information
markmandel authored Mar 2, 2023
1 parent f4a2373 commit 21f1c7f
Show file tree
Hide file tree
Showing 18 changed files with 102 additions and 1 deletion.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ cp terraform.tfvars.sample terraform.tfvars
terraform apply
```

### OAuth Authentication

Terraform is only able to make an [Internal Oauth consent screen](https://support.google.com/cloud/answer/10311615),
which means that only users from your Google organisation will be able to authenticate against the project when
using logging in via the Game Launcher.

You can manually move the consent screen to External (Testing), such that you can allow list accounts outside your
organisation to be able to authenticate against the project, but that has to be a manual step through the
[OAuth Consent screen](https://console.cloud.google.com/apis/credentials/consent).

### Deploy Agones To Agones GKE Clusters

The Agones deployment is in two steps: The Initial Install and the Allocation Endpoint Patch.
Expand Down
26 changes: 26 additions & 0 deletions infrastructure/files/services/frontend-configmap.yaml.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2023 Google LLC All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: v1
kind: ConfigMap
metadata:
name: frontend-service
data:
CLIENT_ID: ${client_id}
CLIENT_SECRET: ${client_secret}
LISTEN_PORT: "8080"
CLIENT_LAUNCHER_PORT: "8082"
PROFILE_SERVICE: http://profile
PING_SERVICE: http://ping-discovery
JWT_KEY: ${jwt_key}
28 changes: 28 additions & 0 deletions infrastructure/services-gke.tf
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,31 @@ resource "local_file" "services-ping-service-account" {
})
filename = "${path.module}/${var.services_directory}/ping-discovery/service-account.yaml"
}

#
# OAuth Credentials for the Frontend Service
#

resource "google_iap_brand" "project_brand" {
support_email = "[email protected]"
application_title = "Global Game Demo"
project = var.project

depends_on = [google_project_service.project]
}

resource "google_iap_client" "project_client" {
display_name = "Global Game Client"
brand = google_iap_brand.project_brand.name
}

# Make the environment configmap for the front service
resource "local_file" "services-frontend-config-map" {
content = templatefile(
"${path.module}/files/services/frontend-configmap.yaml.tpl", {
client_id = google_iap_client.project_client.client_id
client_secret = google_iap_client.project_client.secret
jwt_key = var.frontend-service.jwt_key
})
filename = "${path.module}/${var.services_directory}/frontend/configmap.yaml"
}
8 changes: 7 additions & 1 deletion infrastructure/terraform.tfvars.sample
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ gcp_project_services = [
"spanner.googleapis.com",
"secretmanager.googleapis.com",
"servicecontrol.googleapis.com",
"run.googleapis.com"
"run.googleapis.com",
"iap.googleapis.com"
]


Expand All @@ -107,6 +108,11 @@ services_gke_config = {
}
}

# Frontend Service Config Values
frontend-service = {
jwt_key = "r@nd0m$"
}

# Artifact Registry variables
### NOTE: If you change the Artifact registry location, please make sure to change `cloudbuild.yaml` in
### `services/clouddeploy.yaml;` as it is not dynamically created.
Expand Down
10 changes: 10 additions & 0 deletions infrastructure/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ variable "k8s_service_account_id" {
description = "The kubernetes service account that will impersonate the IAM service account to access Cloud Spanner. This account will be created."
}

### Frontend Service Variables ###

variable "frontend-service" {
type = object({
jwt_key = string
})
description = "Configuration for the frontend service that provides oAuth authentications"
}

### Allocation Endpoint Variables ###

variable "allocation_endpoint" {
Expand All @@ -125,3 +134,4 @@ variable "services_directory" {
type = string
description = "Services Directory for output to Cloud Deploy related files"
}

15 changes: 15 additions & 0 deletions services/frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2023 Google LLC All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

configmap.yaml
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

CLIENT_ID and SECRET_ID need to be generated and fetched from https://console.cloud.google.com/apis/credentials (OAuth 2.0 Client IDs)

For the JWT_KEY, this can be any arbitrary string, but has to be consistent between deployments.
s
# For Local development

Please create a .env file in the same with the following variables:
Expand All @@ -16,6 +18,9 @@ PING_SERVICE=http://localhost:8083
JWT_KEY=<JWT_KEY>
```

* `LISTEN_PORT` is the local port for this Docker container
* `CLIENT_LAUNCHER_PORT` is the port that the launcher uses. There shouldn't be any reason to change this value.

# Building locally

`make build`
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions services/skaffold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ deploy:
manifests:
- ping-discovery/service-account.yaml
- ping-discovery/deployment.yaml
- frontend/configmap.yaml

0 comments on commit 21f1c7f

Please sign in to comment.