1) Create OAuth Apps on Github
Ở đây phần ingress mình chỉ tạo 1 như dưới:
Bổ sung(Tue, Mar 22th, 2022)
Các bạn sẽ cần add thêm path của ingress trên là /auth -> trỏ vào svc spin-gate nữa nhé.
Để khi login xong thì redirect về spinnaker ko bị đứng
2) Config spinnaker to integrate github
giờ bạn exec vào hal
sau đó gõ các command bên dưới
CLIENT_ID=2b7b06b5251b5fa1a6ad
CLIENT_SECRET=xxxxxxxxx87655f0ae01fe4a2a6e3fb9d95c1e8
PROVIDER=github|google|azure
hal config security api edit \
--override-base-url http://spin.nimtechnology.com/gate
hal config security ui edit \
--override-base-url http://spin.nimtechnology.com
hal config security authn oauth2 edit \
--client-id $CLIENT_ID \
--client-secret $CLIENT_SECRET \
--provider $PROVIDER
REDIRECT_URL='http://spin.nimtechnology.com/gate/login'
hal config security authn oauth2 edit --pre-established-redirect-uri $REDIRECT_URL
hal config security authn oauth2 enable
hal deploy apply
>>>Kiểm tra
cat /home/spinnaker/.hal/config
3) Practise login
Bạn thực hiện truy cập:
http://spin.nimtechnology.com/
http://spin.nimtechnology.com/gate/login
4) Filter user login.
Ở phần trên chúng ta chỉ mới authen thôi.
nghĩa là user nào mà đăng nhập github thành công thì sẽ login được vào spinnaker của các bạn. hí hí.
vậy giờ làm sao?
Giờ mình cung cấp cho bạn 1 từ khoá là “userInfoRequirements”
tài liệu tham khảo:
https://youngookkim.tistory.com/40
https://spinnaker.io/docs/setup/other_config/security/authentication/oauth/#restricting-access-based-on-user-info
security:
oauth2:
client:
clientId: changeme
clientSecret: changeme
useCurrentUri: false
scope: user:email
accessTokenUri: https://github.com/login/oauth/access_token
userAuthorizationUri: https://github.com/login/oauth/authorize
resource:
userInfoUri: https://api.github.com/user
userInfoMapping:
email: email
firstName: name
username: login
userInfoRequirements:
email: /(.*)@(company|corp)\.com$/
regex filter email mà mình tìm được
https://www.regextester.com/93886
^[a-z][a-z0-9_.]{5,32}@nimtechnology.com
KIỂM TRA EMAIL HỢP LỆ
+ địa chỉ email phải bắt đầu bằng 1 ký tự + địa chỉ email là tập hợp của các ký tự a-z, 0-9 và có thể có các ký tự như dấu chấm, dấu gạch dưới + độ dài tối thiểu của email là 5, độ dài tối đa là 32 + tên miền của email có thể là tên miền cấp 1 or tên miền cấp 2
5) Authen with google.
https://spinnaker.io/docs/setup/other_config/security/authentication/oauth/google/