Skip to content
This repository has been archived by the owner on Oct 9, 2024. It is now read-only.

Commit

Permalink
Merge pull request #6 from JupiterOne/k8s-infra-improvements
Browse files Browse the repository at this point in the history
Various Kubernetes improvements
  • Loading branch information
austinkelleher authored Jun 29, 2021
2 parents e793a13 + 0d436f4 commit 7f67d6f
Show file tree
Hide file tree
Showing 19 changed files with 176 additions and 87 deletions.
15 changes: 15 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,18 @@ node_modules/
dist/
.env
.eslintcache
.git/
.github/
configs/
docs/
terraform/
test/
CHANGELOG.md
husky.config.js
jest.config.js
lint-staged-config.js
prettier.config.js
.eslintignore
.eslintrc
.gitleaks.yml
.prettierignore
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node-version: [12.x]
node-version: [14.x]
os: [ubuntu-latest, macos-latest]

steps:
Expand Down Expand Up @@ -38,13 +38,13 @@ jobs:
strategy:
fail-fast: false
matrix:
node: [12]
node: [14]

steps:
- name: Setup Node
uses: actions/setup-node@v1
with:
node-version: 12.x
node-version: 14.x

- name: Check out repo
uses: actions/checkout@v2
Expand Down
11 changes: 6 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
FROM node:12-alpine
FROM node:14-alpine

WORKDIR .
ENV JUPITERONE_INTEGRATION_DIR=/opt/jupiterone/integration

# node-gyp/python3 requirement
RUN apk add g++ make python

COPY package.json yarn.lock ./
COPY package.json yarn.lock LICENSE ${JUPITERONE_INTEGRATION_DIR}/
COPY src/ ${JUPITERONE_INTEGRATION_DIR}/src
COPY scripts/ ${JUPITERONE_INTEGRATION_DIR}/scripts

WORKDIR ${JUPITERONE_INTEGRATION_DIR}
RUN yarn install --production

COPY . .

CMD ["yarn", "collect"]
2 changes: 1 addition & 1 deletion configs/clusterRole.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
annotations:
rbac.authorization.kubernetes.io/autoupdate: 'true'
labels:
name: test-read-only
name: jupiterone-integration-cluster-readonly
namespace: default
rules:
- apiGroups:
Expand Down
6 changes: 3 additions & 3 deletions configs/clusterRoleBinding.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: test-binding
name: jupiterone-integration-cluster
subjects:
- kind: ServiceAccount
name: cluster-sa
name: jupiterone-integration-cluster
namespace: default
roleRef:
kind: ClusterRole
name: test-read-only
name: jupiterone-integration-cluster-readonly
apiGroup: rbac.authorization.k8s.io
8 changes: 3 additions & 5 deletions configs/createSecret.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ metadata:
name: jupiterone-integration-secret
type: Opaque
data:
# base64 encoded values
# could use better key-names I'm just unsure of guidelines on that at the moment
jaccountid: <base64encoded jupiterone account id>
japikey: <base64encoded jupiterone api key>
integrationid: <base64encoded integration id>
jupiteroneAccountId: <base64encoded jupiterone account id>
jupiteroneApiKey: <base64encoded jupiterone api key>
jupiteroneIntegrationInstanceId: <base64encoded integration id>
16 changes: 9 additions & 7 deletions configs/cronjobCluster.yaml → configs/cronjobCluster.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ metadata:
labels:
app: integration-cron
spec:
schedule: "*/60 * * * *" # Schedule to run every 10 minutes
schedule: "*/60 * * * *" # Schedule to run every hour
jobTemplate:
spec:
template:
spec:
serviceAccountName: cluster-sa
serviceAccountName: jupiterone-integration-cluster
containers:
- name: integration
image: my-new-image
image: jupiterone-graph-kubernetes
imagePullPolicy: IfNotPresent
env:
# could use better name, but for now:
Expand All @@ -28,15 +28,17 @@ spec:
valueFrom:
secretKeyRef:
name: jupiterone-integration-secret
key: jaccountid
key: jupiteroneAccountId
- name: JUPITERONE_API_KEY
valueFrom:
secretKeyRef:jone-secret
secretKeyRef:
name: jupiterone-integration-secret
key: japikey
key: jupiteroneApiKey
- name: INTEGRATION_INSTANCE_ID
valueFrom:
secretKeyRef:
name: jupiterone-integration-secret
key: integrationid
key: jupiteroneIntegrationInstanceId
- name: IS_RUNNING_TEST
value: 'false'
restartPolicy: Never
12 changes: 7 additions & 5 deletions configs/cronjobNamespace.yaml → configs/cronjobNamespace.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ spec:
spec:
template:
spec:
serviceAccountName: namespace-sa
serviceAccountName: jupiterone-integration
containers:
- name: integration
image: my-new-image
image: jupiterone-graph-kubernetes
imagePullPolicy: IfNotPresent
env:
# could use better name, but for now:
Expand All @@ -28,15 +28,17 @@ spec:
valueFrom:
secretKeyRef:
name: jupiterone-integration-secret
key: jaccountid
key: jupiteroneAccountId
- name: JUPITERONE_API_KEY
valueFrom:
secretKeyRef:
name: jupiterone-integration-secret
key: japikey
key: jupiteroneApiKey
- name: INTEGRATION_INSTANCE_ID
valueFrom:
secretKeyRef:
name: jupiterone-integration-secret
key: integrationid
key: jupiteroneIntegrationInstanceId
- name: IS_RUNNING_TEST
value: 'false'
restartPolicy: Never
12 changes: 7 additions & 5 deletions configs/deploymentCluster.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ spec:
labels:
app: integration
spec:
serviceAccountName: cluster-sa
serviceAccountName: jupiterone-integration-cluster
containers:
- name: integration
image: my-new-image
image: jupiterone-graph-kubernetes
imagePullPolicy: IfNotPresent
env:
# could use better name, but for now:
Expand All @@ -32,14 +32,16 @@ spec:
valueFrom:
secretKeyRef:
name: jupiterone-integration-secret
key: jaccountid
key: jupiteroneAccountId
- name: JUPITERONE_API_KEY
valueFrom:
secretKeyRef:
name: jupiterone-integration-secret
key: japikey
key: jupiteroneApiKey
- name: INTEGRATION_INSTANCE_ID
valueFrom:
secretKeyRef:
name: jupiterone-integration-secret
key: integrationid
key: jupiteroneIntegrationInstanceId
- name: IS_RUNNING_TEST
value: 'false'
12 changes: 7 additions & 5 deletions configs/deploymentNamespace.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ spec:
labels:
app: integration
spec:
serviceAccountName: namespace-sa
serviceAccountName: jupiterone-integration
containers:
- name: integration
image: my-new-image
image: jupiterone-graph-kubernetes
imagePullPolicy: IfNotPresent
env:
# could use better name, but for now:
Expand All @@ -32,14 +32,16 @@ spec:
valueFrom:
secretKeyRef:
name: jupiterone-integration-secret
key: jaccountid
key: jupiteroneAccountId
- name: JUPITERONE_API_KEY
valueFrom:
secretKeyRef:
name: jupiterone-integration-secret
key: japikey
key: jupiteroneApiKey
- name: INTEGRATION_INSTANCE_ID
valueFrom:
secretKeyRef:
name: jupiterone-integration-secret
key: integrationid
key: jupiteroneIntegrationInstanceId
- name: IS_RUNNING_TEST
value: 'false'
10 changes: 5 additions & 5 deletions configs/exampleJob.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ metadata:
spec:
template:
spec:
serviceAccountName: cluster-sa
serviceAccountName: jupiterone-integration-cluster
containers:
- name: integration
image: my-new-image
image: jupiterone-graph-kubernetes
imagePullPolicy: IfNotPresent
env:
# could use better name, but for now:
Expand All @@ -25,16 +25,16 @@ spec:
valueFrom:
secretKeyRef:
name: jupiterone-integration-secret
key: jaccountid
key: jupiteroneAccountId
- name: JUPITERONE_API_KEY
valueFrom:
secretKeyRef:
name: jupiterone-integration-secret
key: japikey
key: jupiteroneApiKey
- name: INTEGRATION_INSTANCE_ID
valueFrom:
secretKeyRef:
name: jupiterone-integration-secret
key: integrationid
key: jupiteroneIntegrationInstanceId
restartPolicy: Never
backoffLimit: 4
14 changes: 8 additions & 6 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ read-only access or cluster-wide read-only access.

1. Create a new service account

`kubectl create sa namespace-sa`
`kubectl create sa jupiterone-integration`

2. Assign namespace read-only access

`kubectl create rolebinding namespace-sa-view --clusterrole=view --serviceaccount=default:namespace-sa --namespace=default`
`kubectl create rolebinding jupiterone-integration-view --clusterrole=view --serviceaccount=default:jupiterone-integration --namespace=default`

### Creating service account with cluster-wide read-only access

1. Create a new service account

`kubectl create sa cluster-sa`
`kubectl create sa jupiterone-integration-cluster`

2. Assign cluster-wide read-only access

Expand All @@ -58,7 +58,8 @@ The integration requires you to store `jupiterone account id`,
`jupiterone api key` and `integration id` as secrets that will be read by the
pod.

Update the `./configs/createSecret.yml` with base64 encoded values.
1. Update the `./configs/createSecret.yml` with base64 encoded values.
2. `kubectl apply -f ./configs/createSecret.yml `

### Building the image and running the integration

Expand All @@ -68,8 +69,9 @@ If you want to build a docker image locally that's also visible to the
minikube/kubernetes, do the following:

1. `eval $(minikube docker-env)`
2. `docker build -t my-new-image .` (will be replaced later with a better name
if we're sure we want to proceed with this authentication method)
2. `docker build -t jupiterone-graph-kubernetes .` (will be replaced later with
a better name if we're sure we want to proceed with this authentication
method)

To deploy the built image as a pod:

Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"access": "public"
},
"scripts": {
"start": "j1-integration collect",
"start": "IS_RUNNING_TEST=true j1-integration collect",
"collect": "./scripts/collect.sh",
"graph": "j1-integration visualize",
"graph:types": "j1-integration visualize-types",
Expand All @@ -26,11 +26,11 @@
"prepack": "yarn build"
},
"devDependencies": {
"@jupiterone/integration-sdk-testing": "^6.0.0"
"@jupiterone/integration-sdk-testing": "^6.7.1"
},
"dependencies": {
"@jupiterone/integration-sdk-core": "^6.0.0",
"@jupiterone/integration-sdk-dev-tools": "^6.0.0",
"@jupiterone/integration-sdk-core": "^6.7.1",
"@jupiterone/integration-sdk-dev-tools": "^6.7.1",
"@kubernetes/client-node": "^0.14.3"
}
}
3 changes: 2 additions & 1 deletion scripts/collect.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#!/usr/bin/env sh
JUPITERONE_API_KEY=$JUPITERONE_API_KEY JUPITERONE_ACCOUNT=$JUPITERONE_ACCOUNT_ID yarn j1-integration run -i $INTEGRATION_INSTANCE_ID

JUPITERONE_API_KEY=$JUPITERONE_API_KEY JUPITERONE_ACCOUNT=$JUPITERONE_ACCOUNT_ID yarn j1-integration run -i $INTEGRATION_INSTANCE_ID
7 changes: 6 additions & 1 deletion src/kubernetes/clients/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ export class CoreClient extends Client {
try {
await this.client.listNamespace();
} catch (err) {
throw new IntegrationProviderAuthenticationError(err.message);
throw new IntegrationProviderAuthenticationError({
cause: err,
endpoint: '/apis/apps/v1/namespaces',
status: 400,
statusText: err.message,
});
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/steps/services/__snapshots__/converters.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ Object {
"externalIPs": undefined,
"externalName": undefined,
"externalTrafficPolicy": undefined,
"function": Array [
"compute",
],
"generation": undefined,
"healthCheckNodePort": undefined,
"ipFamilies": undefined,
Expand Down
Loading

0 comments on commit 7f67d6f

Please sign in to comment.