Skip to content

Commit 81d8edc

Browse files
authored
feat: Add github workflow (#2)
1 parent 36e01c8 commit 81d8edc

File tree

10 files changed

+2185
-83
lines changed

10 files changed

+2185
-83
lines changed

.github/workflows/release.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches:
6+
- "main"
7+
paths:
8+
- 'rockspec/**'
9+
10+
jobs:
11+
release:
12+
name: Release
13+
runs-on: "ubuntu-20.04"
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v2
17+
18+
- name: Install Lua
19+
uses: leafo/gh-actions-lua@v8
20+
21+
- name: Install Luarocks
22+
uses: leafo/gh-actions-luarocks@v4
23+
24+
- name: Extract release name
25+
id: release_env
26+
shell: bash
27+
run: |
28+
title="${{ github.event.head_commit.message }}"
29+
re="^feat: release v*(\S+)"
30+
if [[ $title =~ $re ]]; then
31+
v=v${BASH_REMATCH[1]}
32+
echo "##[set-output name=version;]${v}"
33+
echo "##[set-output name=version_withou_v;]${BASH_REMATCH[1]}"
34+
else
35+
echo "commit format is not correct"
36+
exit 1
37+
fi
38+
39+
- name: Create Release
40+
uses: actions/create-release@v1
41+
env:
42+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
43+
with:
44+
tag_name: ${{ steps.release_env.outputs.version }}
45+
release_name: ${{ steps.release_env.outputs.version }}
46+
draft: false
47+
prerelease: false
48+
49+
- name: Upload to luarocks
50+
env:
51+
LUAROCKS_TOKEN: ${{ secrets.LUAROCKS_TOKEN }}
52+
run: |
53+
luarocks install dkjson
54+
luarocks upload rockspec/lua-resty-saml-${{ steps.release_env.outputs.version_withou_v }}-0.rockspec --api-key=${LUAROCKS_TOKEN}

.github/workflows/test.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
10+
jobs:
11+
build:
12+
runs-on: "ubuntu-20.04"
13+
env:
14+
OPENRESTY_PREFIX: "/usr/local/openresty"
15+
16+
steps:
17+
- uses: actions/checkout@v2
18+
19+
- name: get dependencies
20+
run: |
21+
sudo apt install -y cpanminus build-essential libncurses5-dev libreadline-dev libssl-dev perl lua5.1 liblua5.1-0-dev libxmlsec1-dev
22+
23+
# openresty
24+
wget -O - https://openresty.org/package/pubkey.gpg | sudo apt-key add -
25+
echo "deb http://openresty.org/package/ubuntu $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/openresty.list
26+
sudo apt-get update
27+
sudo apt-get -y install openresty
28+
29+
# Test::Nginx
30+
sudo cpanm --notest Test::Nginx > build.log 2>&1 || (cat build.log && exit 1)
31+
32+
# luarocks
33+
curl -fsSL https://raw.githubusercontent.com/apache/apisix/master/utils/linux-install-luarocks.sh | sudo sh
34+
35+
- name: script
36+
run: |
37+
sudo docker run --rm --name keycloak -d -p 8080:8080 -e KEYCLOAK_ADMIN=admin -e KEYCLOAK_ADMIN_PASSWORD=admin -v $PWD/t/test-realm-keycloak-18.0.2.json:/opt/keycloak/data/import/realm.json quay.io/keycloak/keycloak:18.0.2 start-dev --import-realm
38+
sleep 8
39+
export PATH=$OPENRESTY_PREFIX/nginx/sbin:$OPENRESTY_PREFIX/luajit/bin:$PATH
40+
make test

.gitignore

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
*.o
22
*.so
3-
demo/*
4-
!demo/logs/.gitkeep
5-
!demo/nginx.conf
3+
t/servroot
4+
deps

Makefile

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
VERSION=0.1
1+
INST_PREFIX ?= /usr
2+
INST_LIBDIR ?= $(INST_PREFIX)/lib/lua/5.1
3+
INST_LUADIR ?= $(INST_PREFIX)/share/lua/5.1
4+
INSTALL ?= install
25

3-
# Default locations
46
LUA_INCDIR=/usr/local/openresty/luajit/include/luajit-2.1/
7+
LUAJIT_DIR=/usr/local/openresty/luajit
58

69
CC=gcc
710
CFLAGS=-g -fPIC -O2
@@ -15,18 +18,33 @@ LDFLAGS_ALL=$(LIBFLAG) $(LDFLAGS) $(XMLSEC1_LDFLAGS)
1518
.PHONY: build
1619
build: saml.so
1720

21+
.PHONY: test
22+
test: build deps
23+
prove -r t/
24+
1825
.PHONY: clean
1926
clean:
2027
rm -f *.so *.o
2128

2229
saml.o: src/*.c
2330
$(CC) -c $(CFLAGS_ALL) -o saml.o src/saml.c
2431

25-
src/saml.o:
26-
$(MAKE) -C src saml.o
27-
2832
lua_saml.o: src/lua_saml.c
2933
$(CC) -c $(CFLAGS_ALL) -I$(LUA_INCDIR) -Isrc/ -o $@ $<
3034

3135
saml.so: lua_saml.o saml.o
3236
$(CC) -o $@ $^ $(LDFLAGS_ALL)
37+
38+
.PHONY: install
39+
install:
40+
$(INSTALL) -d $(INST_LUADIR)/resty/
41+
$(INSTALL) lua/resty/*.lua $(INST_LUADIR)/resty/
42+
$(INSTALL) -d $(INST_LIBDIR)/
43+
$(INSTALL) saml.so $(INST_LIBDIR)/
44+
$(INSTALL) -d $(INST_LUADIR)/resty/saml/xsd/
45+
$(INSTALL) xsd/* $(INST_LUADIR)/resty/saml/xsd/
46+
$(INSTALL) t/lib/keycloak.lua $(INST_LUADIR)/resty/saml/
47+
48+
.PHONY: deps
49+
deps:
50+
luarocks install --lua-dir=$(LUAJIT_DIR) rockspec/lua-resty-saml-main-0-0.rockspec --tree=deps --only-deps --local

demo/logs/.gitkeep

Whitespace-only changes.

demo/nginx.conf

Lines changed: 0 additions & 74 deletions
This file was deleted.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package = "lua-resty-saml-main"
2+
version = "0-0"
3+
source = {
4+
url = "git://github.com/api7/lua-resty-saml",
5+
branch = "main",
6+
}
7+
8+
description = {
9+
summary = "SAML 2.0 auth lib for Nginx + Lua",
10+
homepage = "https://github.com/api7/lua-resty-saml",
11+
license = "Apache License 2.0",
12+
}
13+
14+
dependencies = {
15+
"api7-lua-resty-http = 0.2.0",
16+
"lua-resty-jit-uuid = 0.0.7",
17+
"lua-resty-cookie = 0.1.0",
18+
}
19+
20+
build = {
21+
type = "make",
22+
build_variables = {
23+
CFLAGS="$(CFLAGS)",
24+
LIBFLAG="$(LIBFLAG)",
25+
LUA_LIBDIR="$(LUA_LIBDIR)",
26+
LUA_BINDIR="$(LUA_BINDIR)",
27+
LUA_INCDIR="$(LUA_INCDIR)",
28+
LUA="$(LUA)",
29+
},
30+
install_variables = {
31+
INST_PREFIX="$(PREFIX)",
32+
INST_BINDIR="$(BINDIR)",
33+
INST_LIBDIR="$(LIBDIR)",
34+
INST_LUADIR="$(LUADIR)",
35+
INST_CONFDIR="$(CONFDIR)",
36+
},
37+
}

t/README.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# How to setup keycloak for test
2+
3+
## Version
4+
5+
We choose [new keycloak image](https://quay.io/repository/keycloak/keycloak) docker image as test IdP. The version is `18.0.2`.
6+
7+
The lastest version has issues to import client key, so it's pending to check in future:
8+
9+
https://github.com/keycloak/keycloak/issues/13668
10+
11+
https://github.com/keycloak/keycloak/issues/13812
12+
13+
## Configuring keycloak for test
14+
15+
### 1. Run keycloak
16+
17+
```
18+
docker run --rm --name keycloak -d -p 8080:8080 -e KEYCLOAK_ADMIN=admin -e KEYCLOAK_ADMIN_PASSWORD=admin quay.io/keycloak/keycloak:18.0.2 start-dev
19+
```
20+
21+
### 2. Configuring keycloak
22+
23+
#### 2.1 Create realm "test"
24+
25+
#### 2.2 Create User "test"
26+
27+
After completion, in the `Credential` tab page, change password to "test" and disable `Temporary`.
28+
29+
#### 2.3 Create client
30+
31+
##### sp
32+
33+
* Name: sp
34+
* Client Protocol: saml
35+
* Set "Force POST Binding" to "OFF"
36+
* Set Root URL "http://127.0.0.1:8088"
37+
* Valid Redirect URIs: /acs
38+
* Logout Service Redirect Binding URL: /sls
39+
* From the keys tab page, import Signing Key, just paste your cert file content in PEM format
40+
41+
##### sp2
42+
43+
* Name: sp2
44+
* Client Protocol: saml
45+
* Set "Force POST Binding" to "OFF"
46+
* Set Root URL "http://127.0.0.2:8099"
47+
* Valid Redirect URIs: /acs
48+
* Logout Service Redirect Binding URL: /sls
49+
* From the keys tab page, import Signing Key, just paste your cert file content in PEM format
50+
51+
#### 2.4 Check IdP signing key
52+
53+
curl -s http://127.0.0.1:8080/realms/test/protocol/saml/descriptor
54+
55+
Copy and paste `<ds:X509Certificate>` block of the output to a file, e.g. `/tmp/idp.cert`, and use `utils/read_cert.py` to convert it into string.
56+
57+
```
58+
# for test file
59+
python3 utils/read_cert.py /tmp/idp.cert t
60+
61+
# for opts in `saml.new(opts)`
62+
python3 utils/read_cert.py /tmp/idp.cert
63+
```
64+
65+
#### 2.5 export the test realm
66+
67+
```
68+
docker exec -it keycloak bash
69+
/opt/keycloak/bin/kc.sh export --file /tmp/test-realm.json --realm test --users realm_file
70+
docker cp keycloak:/tmp/test-realm.json /tmp/
71+
```
72+
73+
## Run keycloak with import realm
74+
75+
```
76+
docker run --rm --name keycloak -d -p 8080:8080 -e KEYCLOAK_ADMIN=admin -e KEYCLOAK_ADMIN_PASSWORD=admin -v /tmp/test-realm.json:/opt/keycloak/data/import/realm.json quay.io/keycloak/keycloak:18.0.2 start-dev --import-realm
77+
```

0 commit comments

Comments
 (0)