Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

salt: Use csc framework for UI configuration #3181

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
salt: Use csc framework to configure shell UI
Refs: #3175
  • Loading branch information
JBWatenbergScality committed Mar 19, 2021
commit 4cb5f22e51ffc425874f1faefdad3596a9d8861b
1 change: 1 addition & 0 deletions buildchain/buildchain/salt_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ def _get_parts(self) -> Iterator[str]:
Path("salt/metalk8s/addons/ui/deployed/dependencies.sls"),
Path("salt/metalk8s/addons/ui/deployed/ingress.sls"),
Path("salt/metalk8s/addons/ui/deployed/init.sls"),
Path("salt/metalk8s/addons/ui/config/metalk8s-shell-ui-config.yaml.j2"),
Path("salt/metalk8s/addons/ui/config/metalk8s-ui-config.yaml"),
targets.TemplateFile(
task_name="salt/metalk8s/addons/ui/config/metalk8s-theme.yaml",
Expand Down
116 changes: 116 additions & 0 deletions docs/operation/cluster_and_service_configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,24 @@ The default theme for MetalK8s UI are specified below:

See :ref:`csc-ui-theme-customization` to override these defaults.

Shell UI Default Configuration
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

MetalK8s Shell UI provides a common set of features to MetalK8s UI and
any other UI (both control and workload plane) configured to include the
Shell UI component(s).
Features exposed include:
- user authentication using an OIDC provider
- navigation menu items, displayed according to user groups
(retrieved from OIDC)

The default Shell UI configuration values are specified below:

.. literalinclude:: ../../salt/metalk8s/addons/ui/config/metalk8s-shell-ui-config.yaml.j2
:language: yaml
:lines: 3-

See :ref:`csc-shell-ui-config-customization` to override these defaults.

Service Configurations Customization
------------------------------------
Expand Down Expand Up @@ -649,6 +667,104 @@ Once the theme is edited, apply your changes by running:
salt-master-bootstrap -- salt-run state.sls \\
metalk8s.addons.ui.deployed saltenv=metalk8s-|version|

.. _csc-shell-ui-config-customization:

MetalK8s Shell UI Configuration Customization
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Default configuration for MetalK8s Shell UI can be overridden by editing its
Cluster and Service ConfigMap ``metalk8s-shell-ui-config`` in namespace
``metalk8s-ui`` under the key ``data.config\.yaml``.

Changing UI OIDC Configuration
""""""""""""""""""""""""""""""

In order to adapt the OIDC configuration (e.g. the provider URL or
the client ID) used by the UI shareable navigation bar (called Shell UI),
you need to modify its ConfigMap.

For example, in order to replace the default client ID with "ui",
follow these steps:

#. Edit the ConfigMap:

.. code-block:: shell

root@bootstrap $ kubectl --kubeconfig /etc/kubernetes/admin.conf \
edit configmap -n metalk8s-ui \
metalk8s-shell-ui-config

#. Add the following entry:

.. code-block:: yaml

apiVersion: v1
kind: ConfigMap
data:
config.yaml: |-
apiVersion: addons.metalk8s.scality.com/v1alpha1
kind: ShellUIConfig
spec:
# [...]
oidc:
# [...]
clientId: "ui"

#. Apply your changes by running:

.. parsed-literal::

root\@bootstrap $ kubectl exec -n kube-system -c salt-master \\
--kubeconfig /etc/kubernetes/admin.conf \\
salt-master-bootstrap -- salt-run state.sls \\
metalk8s.addons.ui.deployed saltenv=metalk8s-|version|

You can similarly edit the requested scopes through the "scopes" attribute or
the OIDC provider URL through the "providerUrl" attribute.

Changing UI Menu Entries
""""""""""""""""""""""""

To change the UI navigation menu entries, follow these steps:

#. Edit the ConfigMap:

.. code-block:: shell

root@bootstrap $ kubectl --kubeconfig /etc/kubernetes/admin.conf \
edit configmap -n metalk8s-ui \
metalk8s-shell-ui-config

#. Edit the ``options`` field. As an example, we add an entry to
the ``main`` section (there is also a ``subLogin`` section):

.. code-block:: yaml

apiVersion: v1
kind: ConfigMap
data:
config.yaml: |-
apiVersion: addons.metalk8s.scality.com/v1alpha1
kind: ShellUIConfig
spec:
# [...]
options:
# [...]
main:
# [...]
https://www.scality.com/:
en: "Scality"
fr: "Scality"

#. Apply your changes by running:

.. parsed-literal::

root\@bootstrap $ kubectl exec -n kube-system -c salt-master \\
--kubeconfig /etc/kubernetes/admin.conf \\
salt-master-bootstrap -- salt-run state.sls \\
metalk8s.addons.ui.deployed saltenv=metalk8s-|version|

Replicas Count Customization
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
28 changes: 28 additions & 0 deletions salt/metalk8s/addons/ui/config/metalk8s-shell-ui-config.yaml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!jinja|yaml

# Defaults for shell UI configuration
apiVersion: addons.metalk8s.scality.com/v1alpha1
kind: ShellUIConfig
spec:
oidc:
providerUrl: "/oidc"
redirectUrl: "https://{{ grains.metalk8s.control_plane_ip }}:8443/"
clientId: "metalk8s-ui"
responseType: "id_token"
scopes: "openid profile email groups offline_access audience:server:client_id:oidc-auth-client"
userGroupsMapping:
"admin@metalk8s.invalid":
- admin
options:
main:
"https://{{ grains.metalk8s.control_plane_ip }}:8443/":
en: "Platform"
fr: "Plateforme"
"https://{{ grains.metalk8s.control_plane_ip }}:8443/alerts":
en: "Alerts"
fr: "Alertes"
subLogin:
"https://{{ grains.metalk8s.control_plane_ip }}:8443/docs":
en: "Documentation"
fr: "Documentation"

31 changes: 31 additions & 0 deletions salt/metalk8s/addons/ui/deployed/ui-configuration.sls
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ include:
)
%}

{%- set metalk8s_shell_ui_config = salt.metalk8s_kubernetes.get_object(
kind='ConfigMap',
apiVersion='v1',
namespace='metalk8s-ui',
name='metalk8s-shell-ui-config',
)
%}

{%- if metalk8s_ui_config is none %}

Create metalk8s-ui-config ConfigMap:
Expand Down Expand Up @@ -63,3 +71,26 @@ metalk8s-theme ConfigMap already exist:
test.succeed_without_changes: []

{%- endif %}

{%- if metalk8s_shell_ui_config is none %}

Create metalk8s-shell-ui-config ConfigMap:
metalk8s_kubernetes.object_present:
- manifest:
apiVersion: v1
kind: ConfigMap
metadata:
name: metalk8s-shell-ui-config
namespace: metalk8s-ui
data:
config.yaml: |-
apiVersion: addons.metalk8s.scality.com/v1alpha1
kind: ShellUIConfig
spec: {}

{%- else %}

metalk8s-shell-ui-config ConfigMap already exist:
test.succeed_without_changes: []

{%- endif %}
31 changes: 12 additions & 19 deletions salt/metalk8s/addons/ui/deployed/ui.sls.in
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ include:
)
%}

{%- set metalk8s_shell_ui_defaults = salt.slsutil.renderer(
'salt://metalk8s/addons/ui/config/metalk8s-shell-ui-config.yaml.j2', saltenv=saltenv
)
%}

{%- set metalk8s_shell_ui_config = salt.metalk8s_service_configuration.get_service_conf(
'metalk8s-ui', 'metalk8s-shell-ui-config', metalk8s_shell_ui_defaults
)
%}

Create metalk8s-ui deployment:
metalk8s_kubernetes.object_present:
- name: salt://{{ slspath }}/files/metalk8s-ui-deployment.yaml.j2
Expand Down Expand Up @@ -82,25 +92,8 @@ Create shell-ui ConfigMap:
name: shell-ui
namespace: metalk8s-ui
data:
config.json: |
{
"oidc": {
"providerUrl": "/oidc",
"redirectUrl": "https://{{ ingress_control_plane }}/",
"clientId": "metalk8s-ui",
"responseType": "id_token",
"scopes": "openid profile email groups offline_access audience:server:client_id:oidc-auth-client"
},
"options": {
"main": {
"https://{{ ingress_control_plane }}/":{ "en": "Platform", "fr": "Plateforme" },
"https://{{ ingress_control_plane }}/alerts":{ "en": "Alerts", "fr": "Alertes" }
},
"subLogin": {
"https://{{ ingress_control_plane }}/docs":{ "en": "Documentation", "fr": "Documentation" }
}
}
}
config.json: |-
{{ metalk8s_shell_ui_config.spec | tojson }}

Create ui-branding ConfigMap:
metalk8s_kubernetes.object_present:
Expand Down