NOTE: You will authenticate twice in this scenario. Oauth to Snowflake account and then Okta SAML to your Okta account.
Borrowed Python Okta Code from:
https://developer.okta.com/code/python/pysaml2/
- Clone this repo:
git clone https://github.com/sfc-gh-cconner/spcs-python-okta.git
cd spcs-python-okta
- Create a Dockerfile with the following contents:
FROM python:3.8
RUN apt-get update && \
apt-get -y --no-install-recommends install xmlsec1
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY . /usr/src/app
RUN pip install --upgrade pip setuptools && \
pip install --no-cache-dir -r requirements.txt
CMD python app.py
- Build the image:
docker build -t oktaexample:0.1 .
- Create image registry if you don't have one and get the registry URL.
- Tag your image for the registry, login to the registry and push the image:
docker tag oktaexample:0.1 <registry_url>/oktaexample:0.1
docker login <registry_url>
docker push <registry_url>/oktaexample:0.1
- Create the spec yaml file called
oktaexample.yaml
:
spec:
container:
- name: oktaexample
image: <registry_url>/oktaexample:0.5
env:
PORT: 5001
ENTITY_ID: https://<snowflake_url>
OKTA_METADATA_URL: https://okta.com
endpoint:
- name: flask
port: 5001
public: true
networkPolicyConfig:
allowInternetEgress: true
- Push the yaml file and create the service:
create stage if not exists yaml_files;
put file:///<path_to_yaml_file>/oktaexample.yaml yaml_files overwrite=true auto_compress=false;
create service oktaexample
min_instances=1
max_instances=1
compute_pool=TEST_COMPUTE_POOL
spec=@yaml_files/oktaexample.yaml;
- Keep running
desc service oktaexample
until thepublic_endpoints
are available and make note of the public endpoint URL.
- Get a dev okta account or use your existing okta account.
- Sign into the okta admin interface.
- Add a new application.
- On the left, expand Applications.
- Click on Applications.
- Click Create App Integration.
- Select SAML 2.0.
- Click Next.
- Give the App a name.
- CLick Next.
- For the Single Sign On URL enter the URL from the service endpoint above followed by
/saml/sso/example-okta-com
, for example:
https://<id>-<org_name>-<alias>.snowflakecomputing.app/saml/sso/example-okta-com
- For the audience enter your Snowflake URL including
https
. Just like we did forENTITY_ID
in the Yaml file. NameID
format should beEmailAddress
.- Application username should be
Okta username.
- For attribute statements, add:
FirstName
LastName
Email
- Click Next.
- Click Finish.
- On the Sign On page that should now be showing, copy the
Metadata URL
.
- Update the spec file:
spec:
container:
- name: oktaexample
image: <registry_url>/oktaexample:0.5
env:
PORT: 5001
ENTITY_ID: https://<snowflake_url>
OKTA_METADATA_URL: <Metadata URL from previous step>
endpoint:
- name: flask
port: 5001
public: true
networkPolicyConfig:
allowInternetEgress: true
- Put the file and redeploy by suspending and resuming the service. This should trigger re-reading the new spec file.
put file:///<path_to_yaml_file>/oktaexample.yaml yaml_files overwrite=true auto_compress=false;
alter service oktaexample suspend;
alter service oktaexample resume;
- Go to the endpoint URL for the service. There will be a login link. Click the link and you should be redirected to Okta for authentication and back to the application as authenticated.