Skip to content

Commit e802b8f

Browse files
committed
ga
1 parent d541b9d commit e802b8f

File tree

1,240 files changed

+703079
-36
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,240 files changed

+703079
-36
lines changed

.github/workflows/blank.yml

Lines changed: 0 additions & 36 deletions
This file was deleted.

.github/workflows/docker-build.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Build and Push Docker Images
2+
3+
on:
4+
push:
5+
branches:
6+
- '**'
7+
paths:
8+
- '.github/workflows/docker-build.yml'
9+
workflow_dispatch:
10+
inputs:
11+
services:
12+
description: 'Services to build (comma-separated or "all")'
13+
required: true
14+
default: 'all'
15+
type: choice
16+
options:
17+
- all
18+
- keycloak
19+
- keycloak-21.1.2
20+
- keycloak-postgres-query
21+
- kong-api-scripts
22+
- postgresql-backup
23+
- redis-backup
24+
- sunbird-yugabyte-migrations
25+
26+
jobs:
27+
build-push:
28+
runs-on: ubuntu-latest
29+
strategy:
30+
matrix:
31+
service:
32+
- name: keycloak
33+
path: scripts/keycloak
34+
- name: keycloak-21.1.2
35+
path: scripts/keycloak-21.1.2
36+
- name: keycloak-postgres-query
37+
path: scripts/keycloak-postgres-query
38+
- name: kong-api-scripts
39+
path: scripts/kong-api-scripts
40+
- name: postgresql-backup
41+
path: scripts/postgresql-backup
42+
- name: redis-backup
43+
path: scripts/redis-backup
44+
- name: sunbird-yugabyte-migrations
45+
path: scripts/sunbird-yugabyte-migrations
46+
47+
steps:
48+
- name: Checkout
49+
if: ${{ github.event_name == 'push' || github.event.inputs.services == 'all' || contains(github.event.inputs.services, matrix.service.name) }}
50+
uses: actions/checkout@v4
51+
52+
- name: Set up Docker Buildx
53+
if: ${{ github.event_name == 'push' || github.event.inputs.services == 'all' || contains(github.event.inputs.services, matrix.service.name) }}
54+
uses: docker/setup-buildx-action@v3
55+
56+
- name: Login to GHCR
57+
if: ${{ github.event_name == 'push' || github.event.inputs.services == 'all' || contains(github.event.inputs.services, matrix.service.name) }}
58+
uses: docker/login-action@v3
59+
with:
60+
registry: ghcr.io
61+
username: ${{ github.actor }}
62+
password: ${{ secrets.GITHUB_TOKEN }}
63+
64+
- name: Build and Push
65+
if: ${{ github.event_name == 'push' || github.event.inputs.services == 'all' || contains(github.event.inputs.services, matrix.service.name) }}
66+
uses: docker/build-push-action@v5
67+
with:
68+
context: ${{ matrix.service.path }}
69+
platforms: linux/amd64
70+
push: true
71+
tags: ghcr.io/${{ github.repository_owner }}/${{ matrix.service.name }}:latest
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
sunbird_admin_api_token: {{api_admin_jwt}}
3+
sunbird_anonymous_register_token: {{portal_anonymous_register_jwt}}
4+
sunbird_loggedin_register_token: {{portal_loggedin_register_jwt}}
5+
sunbird_anonymous_default_token: {{portal_anonymous_fallback_token_jwt}}
6+
sunbird_logged_default_token: {{portal_loggedin_fallback_token_jwt}}
7+
adminutil_learner_api_auth_key: {{adminutil_learner_api_token_jwt}}

scripts/jwt-keys.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import os
2+
import jwt
3+
import sys
4+
5+
# Predefined map of keys and secrets
6+
consumer_list = ["api_admin", "mobile_admin", "mobile_device", "mobile_devicev2", "portal_anonymous_register", "portal_loggedin_register", "portal_anonymous", "portal_loggedin", "portal_anonymous_fallback_token", "portal_loggedin_fallback_token", "adminutil_learner_api_token"]
7+
8+
def generate_jwt_token(key, secret, random_string):
9+
# Concatenate the random string to the secret
10+
secret_with_random = secret + random_string
11+
12+
# Create the token payload
13+
payload = {
14+
"iss": key
15+
}
16+
17+
# Generate the JWT token
18+
jwt_token = jwt.encode(payload, secret_with_random, algorithm="HS256")
19+
20+
return jwt_token
21+
22+
def replace_placeholders(template_content, token_dict):
23+
for key, token in token_dict.items():
24+
placeholder = f"{{{{{key}}}}}"
25+
template_content = template_content.replace(placeholder, token)
26+
27+
return template_content
28+
29+
if __name__ == "__main__":
30+
# Check if the random string is provided as a command-line argument
31+
if len(sys.argv) != 2:
32+
print("Usage: python script.py <random_string>")
33+
sys.exit(1)
34+
35+
random_string = sys.argv[1]
36+
37+
# Validate the length of the random string
38+
if not (12 <= len(random_string) <= 24):
39+
print("Error: The random string must be between 12 and 24 characters in length.")
40+
sys.exit(1)
41+
42+
# Get the script directory
43+
script_directory = os.path.dirname(os.path.realpath(__file__))
44+
45+
# Construct the template file path relative to the script location
46+
template_file_name = os.path.join(script_directory, "global-values-jwt-tokens.yaml.tpl")
47+
48+
# Generate JWT tokens for each key in the map
49+
token_dict = {}
50+
for consumer in consumer_list:
51+
token = generate_jwt_token(consumer, consumer, random_string)
52+
token_dict[f"{consumer}_jwt"] = token
53+
54+
# Read the template file
55+
with open(template_file_name, "r") as template_file:
56+
template_content = template_file.read()
57+
58+
# Replace placeholders with JWT tokens
59+
modified_content = replace_placeholders(template_content, token_dict)
60+
61+
# Write the modified content to a new file
62+
output_file_name = os.path.join(script_directory,"global-values-jwt-tokens.yaml")
63+
with open(output_file_name, "w") as output_file:
64+
output_file.write(modified_content)
65+
66+
print(f"Modified content written to {output_file_name}")

scripts/keycloak-21.1.2/Dockerfile

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
FROM quay.io/keycloak/keycloak:21.1.2 AS builder
3+
4+
ENV KC_FEATURES=token-exchange
5+
ENV KC_HEALTH_ENABLED=true
6+
ENV KC_METRICS_ENABLED=true
7+
8+
9+
FROM quay.io/keycloak/keycloak:21.1.2
10+
COPY --from=builder /opt/keycloak/ /opt/keycloak/
11+
12+
13+
COPY ./conf/ /opt/keycloak/conf/
14+
COPY ./providers/ /opt/keycloak/providers/
15+
COPY ./themes/ /opt/keycloak/themes/
16+
COPY ./imports/ /opt/keycloak/imports/
17+
18+
19+
USER root
20+
RUN chown -R keycloak:keycloak /opt/keycloak
21+
USER keycloak
22+
23+
24+
ENV KC_PROXY=edge
25+
ENV KC_HOSTNAME_STRICT=false
26+
ENV KC_HOSTNAME_STRICT_HTTPS=false
27+
ENV KC_HTTP_RELATIVE_PATH=/auth
28+
ENV KC_SPI_LOGIN_PROTOCOL_OPENID_CONNECT_LEGACY_LOGOUT_REDIRECT_URI=true
29+
30+
RUN /opt/keycloak/bin/kc.sh build
31+
32+
EXPOSE 8080
33+
34+
WORKDIR /opt/keycloak
35+
36+
ENTRYPOINT ["/opt/keycloak/bin/kc.sh"]
37+
CMD ["start", "--optimized", "--import-realm", "--spi-connections-jpa-legacy-migration-strategy=update", "--spi-login-protocol-openid-connect-suppress-logout-confirmation-screen=true"]

scripts/keycloak-21.1.2/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Sunbird Keycloak Setup
2+
3+
4+
## Configuration Values
5+
Here are the configuration values pulled from `keycloak.conf`:
6+
- **Database Type**: `db=postgres`
7+
- **Database Username**: `db-username=postgres`
8+
- **Database Password**: `db-password=postgres`
9+
- **Database URL**: `db-url=jdbc:postgresql://localhost:5432/keycloak?sslmode=require`
10+
- **HTTP Relative Path**: `http-relative-path=/auth`
11+
12+
## Configuration Values with Placeholders
13+
14+
Any placeholders in the pattern `{{ .Values.<key> }}` in `imports/sunbird-realm.json` need to be filled with appropriate values during local setup.
15+
16+
## Docker Build Command
17+
To build the Docker image, use the following command:
18+
```bash
19+
docker build -t my-keycloak-image .
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Configure the server
2+
====================
3+
4+
Files in this directory are used to configure the server. Please consult the [configuration guides](https://www.keycloak.org/guides#server) for more information.
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright 2019 Red Hat, Inc. and/or its affiliates
4+
~ and other contributors as indicated by the @author tags.
5+
~
6+
~ Licensed under the Apache License, Version 2.0 (the "License");
7+
~ you may not use this file except in compliance with the License.
8+
~ You may obtain a copy of the License at
9+
~
10+
~ http://www.apache.org/licenses/LICENSE-2.0
11+
~
12+
~ Unless required by applicable law or agreed to in writing, software
13+
~ distributed under the License is distributed on an "AS IS" BASIS,
14+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
~ See the License for the specific language governing permissions and
16+
~ limitations under the License.
17+
-->
18+
19+
<infinispan
20+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
21+
xsi:schemaLocation="urn:infinispan:config:14.0 http://www.infinispan.org/schemas/infinispan-config-14.0.xsd"
22+
xmlns="urn:infinispan:config:14.0">
23+
24+
<cache-container name="keycloak">
25+
<transport lock-timeout="60000"/>
26+
<local-cache name="realms">
27+
<encoding>
28+
<key media-type="application/x-java-object"/>
29+
<value media-type="application/x-java-object"/>
30+
</encoding>
31+
<memory max-count="10000"/>
32+
</local-cache>
33+
<local-cache name="users">
34+
<encoding>
35+
<key media-type="application/x-java-object"/>
36+
<value media-type="application/x-java-object"/>
37+
</encoding>
38+
<memory max-count="10000"/>
39+
</local-cache>
40+
<distributed-cache name="sessions" owners="2">
41+
<expiration lifespan="-1"/>
42+
</distributed-cache>
43+
<distributed-cache name="authenticationSessions" owners="2">
44+
<expiration lifespan="-1"/>
45+
</distributed-cache>
46+
<distributed-cache name="offlineSessions" owners="2">
47+
<expiration lifespan="-1"/>
48+
</distributed-cache>
49+
<distributed-cache name="clientSessions" owners="2">
50+
<expiration lifespan="-1"/>
51+
</distributed-cache>
52+
<distributed-cache name="offlineClientSessions" owners="2">
53+
<expiration lifespan="-1"/>
54+
</distributed-cache>
55+
<distributed-cache name="loginFailures" owners="2">
56+
<expiration lifespan="-1"/>
57+
</distributed-cache>
58+
<local-cache name="authorization">
59+
<encoding>
60+
<key media-type="application/x-java-object"/>
61+
<value media-type="application/x-java-object"/>
62+
</encoding>
63+
<memory max-count="10000"/>
64+
</local-cache>
65+
<replicated-cache name="work">
66+
<expiration lifespan="-1"/>
67+
</replicated-cache>
68+
<local-cache name="keys">
69+
<encoding>
70+
<key media-type="application/x-java-object"/>
71+
<value media-type="application/x-java-object"/>
72+
</encoding>
73+
<expiration max-idle="3600000"/>
74+
<memory max-count="1000"/>
75+
</local-cache>
76+
<distributed-cache name="actionTokens" owners="2">
77+
<encoding>
78+
<key media-type="application/x-java-object"/>
79+
<value media-type="application/x-java-object"/>
80+
</encoding>
81+
<expiration max-idle="-1" lifespan="-1" interval="300000"/>
82+
<memory max-count="-1"/>
83+
</distributed-cache>
84+
</cache-container>
85+
</infinispan>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
db=postgres
2+
db-username=postgres
3+
db-password=postgres
4+
db-url=jdbc:postgresql://localhost:5432/keycloak?sslmode=require
5+
http-relative-path=/auth
6+
log=console,file
7+
log-level=INFO,com.arjuna:WARN,io.jaegertracing.Configuration:WARN,org.jboss.as.config:DEBUG,sun.rmi:WARN,org.keycloak:INFO
8+
log-console-color=true
9+
log-console-output=default
10+
log-file-output=default
11+
log-console-format='%K{level}%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%e%n'
12+
log-file-format='%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c] (%t) %s%e%n'
13+
14+
DEBUG='true'
15+
DEBUG_PORT='*:8787'
16+
spi-login-logout-skip-confirmation=true

0 commit comments

Comments
 (0)