Skip to content

Commit e30193d

Browse files
iromlimoabu
andauthored
feat: enhance Google Spanner support (#19)
* feat: enhance spanner support * fix: conform to latest jans-pycloudlib * fix: do not update persistence if keystore path is unchanged * chore: update jans-pycloudlib * chore: update jans-pycloudlib * chore: update jans-pycloudlib * feat: add feature to customize Jetty request header size * chore: update jans-auth-server * chore: update jans-auth-server Co-authored-by: Mohammad Abudayyeh <47318409+moabu@users.noreply.github.com>
1 parent 4d9b16b commit e30193d

6 files changed

Lines changed: 36 additions & 10 deletions

File tree

Dockerfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ RUN wget -q https://github.com/fabioz/PyDev.Debugger/archive/refs/tags/pydev_deb
5151
# ===========
5252

5353
ENV CN_VERSION=1.0.0-SNAPSHOT
54-
ENV CN_BUILD_DATE='2021-06-01 16:06'
54+
ENV CN_BUILD_DATE='2021-06-22 16:57'
5555
ENV CN_SOURCE_URL=https://maven.jans.io/maven/io/jans/jans-auth-server/${CN_VERSION}/jans-auth-server-${CN_VERSION}.war
5656

5757
# Install Jans Auth
@@ -156,7 +156,9 @@ ENV CN_PERSISTENCE_TYPE=ldap \
156156
CN_COUCHBASE_BUCKET_PREFIX=jans \
157157
CN_COUCHBASE_TRUSTSTORE_ENABLE=true \
158158
CN_COUCHBASE_KEEPALIVE_INTERVAL=30000 \
159-
CN_COUCHBASE_KEEPALIVE_TIMEOUT=2500
159+
CN_COUCHBASE_KEEPALIVE_TIMEOUT=2500 \
160+
CN_GOOGLE_SPANNER_INSTANCE_ID="" \
161+
CN_GOOGLE_SPANNER_DATABASE_ID=""
160162

161163
# ===========
162164
# Generic ENV

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,6 @@ The following environment variables are supported by the container:
7373
- `CN_SYNC_JKS_INTERVAL`: Interval of JKS sync in seconds (if needed); obsolete.
7474
- `GOOGLE_PROJECT_ID`: Google Project ID (default to empty string). Used when `CN_CONFIG_ADAPTER` or `CN_SECRET_ADAPTER` set to `google`.
7575
- `GOOGLE_APPLICATION_CREDENTIALS`: Path to Google credentials JSON file (default to `/etc/jans/conf/google-credentials.json`). Used when `CN_CONFIG_ADAPTER` or `CN_SECRET_ADAPTER` set to `google`.
76+
- `CN_GOOGLE_SPANNER_INSTANCE_ID`: Google Spanner instance ID.
77+
- `CN_GOOGLE_SPANNER_DATABASE_ID`: Google Spanner database ID.
78+
- `CN_JETTY_REQUEST_HEADER_SIZE`: Maximum size of request header accepted by Jetty (default to `8192`).

conf/jans-spanner.properties.tmpl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,8 @@ connection.pool.create-max-wait-time-millis=20000
2323
# Maximum allowed statement result set size
2424
statement.limit.default-maximum-result-size=1000
2525

26+
# Maximum allowed delete statement result set size
27+
statement.limit.maximum-result-delete-size=10000
28+
2629
binaryAttributes=objectGUID
2730
certificateAttributes=userCertificate

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
-e git+https://github.com/JanssenProject/jans-pycloudlib@a49f267f16a75965756d475d0e8102ad7cde2010#egg=jans-pycloudlib
1+
-e git+https://github.com/JanssenProject/jans-pycloudlib@a6ce9a098be01b4edcb69fbeee7f0bf745130c44#egg=jans-pycloudlib

scripts/bootstrap.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ def modify_jetty_xml():
4545
flags=re.DOTALL | re.M,
4646
)
4747

48+
# set custom request header size
49+
req_header_size = os.environ.get("CN_JETTY_REQUEST_HEADER_SIZE", "8192")
50+
updates = re.sub(
51+
r'(<Set name="requestHeaderSize"><Property name="jetty.httpConfig.requestHeaderSize" deprecated="jetty.request.header.size" default=)"\d+"( /></Set>)',
52+
r'\1"{}"\2'.format(req_header_size),
53+
updates,
54+
flags=re.DOTALL | re.M,
55+
)
56+
4857
with open(fn, "w") as f:
4958
f.write(updates)
5059

scripts/keystore_mod.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from jans.pycloudlib.persistence.couchbase import get_couchbase_password
77
from jans.pycloudlib.persistence.ldap import LdapClient
88
from jans.pycloudlib.persistence.sql import SQLClient
9+
from jans.pycloudlib.persistence.spanner import SpannerClient
910

1011

1112
class BasePersistence:
@@ -112,11 +113,24 @@ def modify_auth_config(self, id_, rev, conf_dynamic):
112113
return modified
113114

114115

116+
class SpannerPersistence(SqlPersistence):
117+
def __init__(self, manager):
118+
self.client = SpannerClient()
119+
120+
121+
_backend_classes = {
122+
"ldap": LdapPersistence,
123+
"couchbase": CouchbasePersistence,
124+
"sql": SqlPersistence,
125+
"spanner": SpannerPersistence,
126+
}
127+
128+
115129
def modify_keystore_path(manager, path, jwks_uri):
116130
persistence_type = os.environ.get("CN_PERSISTENCE_TYPE", "ldap")
117131
ldap_mapping = os.environ.get("CN_PERSISTENCE_LDAP_MAPPING", "default")
118132

119-
if persistence_type in ("ldap", "couchbase", "sql"):
133+
if persistence_type in ("ldap", "couchbase", "sql", "spanner"):
120134
backend_type = persistence_type
121135
else:
122136
# persistence_type is hybrid
@@ -126,12 +140,7 @@ def modify_keystore_path(manager, path, jwks_uri):
126140
backend_type = "couchbase"
127141

128142
# resolve backend
129-
if backend_type == "ldap":
130-
backend = LdapPersistence(manager)
131-
elif backend_type == "couchbase":
132-
backend = CouchbasePersistence(manager)
133-
else:
134-
backend = SqlPersistence(manager)
143+
backend = _backend_classes[backend_type](manager)
135144

136145
config = backend.get_auth_config()
137146
if not config:

0 commit comments

Comments
 (0)