↓ Skip to main content
A low-poly picture of a dock with five teal shipping containers in one row. One orange container hangs on a hook above the free place at the end of the row.

Deploying Into a MAS Namespace

One command deploys our skeleton of a companion app. Behind it stand a few objects in the namespace of the suite, and the order in which our script creates them. This page goes through both, and through the way back out.

MAS 9.2 series companion app deployment

From Skeleton to a Running App ran the command. This page opens it up. We ran everything here on our test system, on the MAS 9.2 series, with a login that has rights in the namespace of the suite. The cluster uses path routing.

The objects
#

ObjectMade byWhat it is for
Certificatethe manifestTLS for the pod, and the certificate the pod shows inside the cluster
ServiceAccountthe manifestthe identity of the pod on the cluster
PersistentVolumeClaimthe manifesta place for files of the app
NetworkPolicythe manifestwho may talk to the pod, and where the pod may talk to
Deploymentthe manifestthe pod, its settings and its mounts
Servicethe manifestport 443 to port 9443 of the pod
Secret of the sign-in clientthe scriptthe client id and a generated client secret
Routethe scriptthe way in from the browser
Jobthe scriptregisters the app at the identity provider; on a repeat run it finds the client and leaves it

The manifest is one file with placeholders, and the script fills them in. These are its first four objects:

# App objects for a MAS companion container. Tokens (__APP__, __NS__, __DOMAIN__,
# __HOST__, __IMAGE__, __ISSUER__, __ROUTING_MODE__, __BASE_PATH__, __AUTH_OIDC__,
# __AUTH_BASE__, __MANAGE_URL__) are substituted by deploy.sh. The oauth-client
# Secret and the Route are created by deploy.sh (secret generated; route needs the
# issued CA), so they are not in this file.
---
# The certificate of the app, issued by the internal ClusterIssuer of the suite. The pod
# serves HTTPS with it and presents it to the internal API.
apiVersion: cert-manager.io/v1
kind: Certificate
metadata: { name: __APP__-cert-internal, namespace: __NS__ }
spec:
  secretName: __APP__-cert-internal
  commonName: __APP__.svc
  dnsNames: [__APP__.svc, __APP__.__NS__.svc, __APP__.__NS__.svc.cluster.local]
  duration: 8760h
  renewBefore: 720h
  issuerRef: { name: __ISSUER__, kind: ClusterIssuer, group: cert-manager.io }
---
# The identity of the pod on the cluster. It has no role binding: the app asks the cluster for nothing.
apiVersion: v1
kind: ServiceAccount
metadata: { name: __APP__, namespace: __NS__ }
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata: { name: __APP__-workspace, namespace: __NS__ }
spec: { accessModes: [ReadWriteOnce], resources: { requests: { storage: 2Gi } } }
---
# This policy opens port 9443 for incoming traffic and all outgoing traffic for the pod
# of the app. On our test system the pod could not look up a name without it.
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata: { name: __APP__, namespace: __NS__ }
spec:
  podSelector: { matchLabels: { app: __APP__ } }
  policyTypes: [Ingress, Egress]
  ingress: [{ ports: [{ port: 9443, protocol: TCP }] }]
  egress: [{}]

The Deployment and the Service follow in the same file. The Deployment has one replica and one container, mounts the certificate and the sign-in client read-only, and gets its settings as environment variables.

The service account has no role binding. The app asks the cluster for nothing, so its account needs no right there.

The order
#

d2 diagram d2 diagram

The six steps of the deploy script. Step 5 needs the image, the certificate and the network policy of the steps before it.

The script makes the Route after the certificate is ready. The Route has the termination reencrypt, and it carries the certificate of the authority that issued the pod’s certificate as its destination CA. The script waits until the certificate is ready, reads that authority from the issued secret, and writes it into the Route:

say "4. wait for the certificate, then make the Route with the issued CA"
oc wait --for=condition=Ready "certificate/$APP-cert-internal" -n "$NS" --timeout=180s
ROUTE_PATH=""; [ -n "$BASE_PATH" ] && ROUTE_PATH="  path: $BASE_PATH"
CA=$(oc get secret "$APP-cert-internal" -n "$NS" -o jsonpath='{.data.ca\.crt}' | base64 -d | sed 's/^/      /')
cat <<YAML | oc apply -n "$NS" -f -
apiVersion: route.openshift.io/v1
kind: Route
metadata: { name: $APP, namespace: $NS }
spec:
  host: $HOST
$ROUTE_PATH
  to: { kind: Service, name: $APP, weight: 100 }
  port: { targetPort: $APP }
  tls:
    termination: reencrypt
    destinationCACertificate: |
$CA
YAML

We apply the network policy together with the pod. We tested what it does by taking it away. With the policy, a probe through the Route answered 200, and from inside the pod the internal API and the identity provider answered 200. Twelve seconds after we deleted the policy, the probe through the Route still answered 200. From inside the pod, both calls failed, and the error was a failed name lookup. The pod itself stayed running. We applied the policy again and all three answers were back.

So on our test system the pod needed the policy to look up a name. The registration Job has the same label as the app, and the policy covers it too.

The script registers the sign-in client after the pod and the Route exist. The Job in step 5 registers the app at the identity provider of the suite, with the callback address of the app. It runs inside the cluster, in the image of the app, and it reads the administrator credentials of the identity provider from a secret of the namespace. They never leave the cluster. On a first run the Job printed “coreidp HTTP 201” and “Registration OK”.

Path routing and subdomain routing
#

The suite has one of two routing modes, and it is fixed when the suite is installed. Our script reads the mode from the cluster and sets these things by it:

Path routingSubdomain routing
Host of the Routethe host of the suitea host of the app’s own
Path of the Route/<app>none
Base path of the app/<app>empty
Addresses of the sign-inunder the host of the suiteunder the host auth.<domain>

We ran the path routing column for this page. The subdomain column follows our script, and the skeleton ran that way on an earlier install of our test system.

The way back out
#

A removal has an order as well. The app’s client at the identity provider is deleted by a Job, and that Job needs the image, the certificate and the network policy of the app. So the client goes first and the objects after it.

Our first removal went wrong, and the script said it went well. The Job could not be created, by an error of ours. The script went on, deleted every object and printed “fully removed”. The client stayed registered.

We saw what that costs on the next deploy. The registration Job found the client and left it as it was. The deploy had made a new client secret, and the registered client still had the old one. A sign-in then ended on the app’s failure page with the text “Authentication failed”.

We changed the script: when the client is not removed, it stops and deletes nothing. The second removal began like this, went on to delete the objects, and left no object with the app’s name:

== 1. de-register OIDC client 'mas-companion-skeleton' from coreidp (RFC 7592 DELETE, in-cluster Job)
DELETE client HTTP 204

A fresh deploy after that registered the client again with 201, and the sign-in worked.

What we take from it
#

  • Wait for the certificate before you make the Route. The Route carries the authority from the issued secret.
  • Ship a network policy with the app. Without ours, the pod could not look up a name.
  • Remove the sign-in client first. The Job that removes it needs what the removal deletes next.
  • Let a removal fail loudly. Ours deleted everything after its first step had failed, and the sign-in after the next deploy failed.

What to read next#

Logging In Through MAS follows the sign-in that step 5 prepares. Anatomy of a MAS Companion App shows the same kinds of objects on a released app of ours. From Skeleton to a Running App has the two failures of the first deploy.