Building Gateway Image with Policies from Policy Hub using apipctl #516
Replies: 15 comments 38 replies
-
@renuka-fernando, I have few concerns on this newly proposed implementation.
|
Beta Was this translation helpful? Give feedback.
-
|
Shall we go with the following command apipctl gateway image build \
--tag <image-tag> \
[-f <policy-manifest-yaml-file>]
[--repository <image-repository>] \
[--gateway-builder <gateway-builder-image>] \
[--gateway-controller-base-image <gateway-controller-base-image>] \
[--router-base-image <router-base-image>] \
[--push] \
[--no-cache] \
[--platform <platform>] \
[--offline] \
[--output-dir <output_dir>]And there are other commands after the So having the apipctl command discussion: #356 BTW, I see some commands are not consistent. This should be discussed in the above GH discussion. apipctl gateway add # add is a verb here
vs
apipctl gateway api list # api is a resource herecc: @nuwand, @malinthaprasan, @piyumaldk |
Beta Was this translation helpful? Give feedback.
-
|
When --offline is true
|
Beta Was this translation helpful? Give feedback.
-
|
Here is the temp dir structure discussed in the discussion above. ❯ tree .
.
├── output
├── policies
│ ├── basic-auth
│ │ ├── v1.0.0
│ │ │ ├── basicauth.go
│ │ │ ├── go.mod
│ │ │ └── policy-definition.yaml
│ │ └── v1.0.1
│ │ ├── basicauth.go
│ │ ├── go.mod
│ │ └── policy-definition.yaml
│ ├── content-length-guardrail
│ │ └── v0.1.0
│ │ ├── contentlengthguardrail.go
│ │ ├── go.mod
│ │ └── policy-definition.yaml
│ ├── json-schema-guardrail
│ │ └── v0.1.0
│ │ ├── go.mod
│ │ ├── jsonschemaguardrail.go
│ │ └── policy-definition.yaml
│ ├── jwt-authentication
│ │ └── v0.1.0
│ │ ├── go.mod
│ │ ├── go.sum
│ │ ├── jwtauth.go
│ │ ├── jwtauth_test.go
│ │ └── policy-definition.yaml
│ ├── mcp-auth
│ │ └── v0.1.0
│ │ ├── go.mod
│ │ ├── go.sum
│ │ ├── mcp-auth.go
│ │ ├── mcp-auth_test.go
│ │ └── policy-definition.yaml
│ ├── modify-headers
│ │ └── v1.0.0
│ │ ├── go.mod
│ │ ├── modifyheaders.go
│ │ └── policy-definition.yaml
│ ├── pii-masking-regex
│ │ └── v0.1.0
│ │ ├── go.mod
│ │ ├── piimaskingregex.go
│ │ └── policy-definition.yaml
│ ├── regex-guardrail
│ │ └── v0.1.0
│ │ ├── go.mod
│ │ ├── policy-definition.yaml
│ │ └── regexguardrail.go
│ ├── respond
│ │ └── v1.0.0
│ │ ├── go.mod
│ │ ├── policy-definition.yaml
│ │ └── respond.go
│ ├── sentence-count-guardrail
│ │ └── v0.1.0
│ │ ├── go.mod
│ │ ├── policy-definition.yaml
│ │ └── sentencecountguardrail.go
│ ├── url-guardrail
│ │ └── v0.1.0
│ │ ├── go.mod
│ │ ├── policy-definition.yaml
│ │ └── urlguardrail.go
│ └── word-count-guardrail
│ └── v0.1.0
│ ├── go.mod
│ ├── policy-definition.yaml
│ └── wordcountguardrail.go
└── policy-manifest-lock.yamlSample command docker run --rm \
-v $(pwd):/workspace \
ghcr.io/renuka-fernando/api-platform/gateway-builder:0.1.0-SNAPSHOT |
Beta Was this translation helpful? Give feedback.
-
|
Manifest Dir |
Beta Was this translation helpful? Give feedback.
-
|
@piyumaldk and I discussed to do the following.
|
Beta Was this translation helpful? Give feedback.
-
New Suggestion for the CommandDefault values:
SampleIf the following command is executed in |
Beta Was this translation helpful? Give feedback.
-
Internal Commandsdocker run --rm \
-v <temp-dir>:/workspace \
<gateway-builder-image> \
-gateway-controller-base-image <gateway-controller-base-image> \
-router-base-image <router-base-image>
cd <temp-dir>/output/policy-engine
docker build -t [--no-cache] <image-repository>/<gateway-name>-policy-engine:<gateway-version> .
cd <temp-dir>/output/gateway-controller
docker build -t [--no-cache] <image-repository>/<gateway-name>-gateway-controller:<gateway-version> .
cd <temp-dir>/output/router
docker build -t [--no-cache] <image-repository>/<gateway-name>-router:<gateway-version> .
if [--push] is set then
docker push <image-repository>/<gateway-name>-policy-engine:<gateway-version>
docker push <image-repository>/<gateway-name>-gateway-controller:<gateway-version>
docker push <image-repository>/<gateway-name>-router:<gateway-version>
if [--platform] is set then
# --push should be true
cd <temp-dir>/output/policy-engine
docker buildx build --platform <platform> --push -t <image-repository>/<gateway-name>-policy-engine:<gateway-version> .
cd <temp-dir>/output/gateway-controller
docker buildx build --platform <platform> --push -t <image-repository>/<gateway-name>-gateway-controller:<gateway-version> .
cd <temp-dir>/output/router
docker buildx build --platform <platform> --push -t <image-repository>/<gateway-name>-router:<gateway-version> . |
Beta Was this translation helpful? Give feedback.
-
Policy Naming ConventionPolicy Definition FileName in manifest file can be in any format in ASCII. name: Basic Auth
version: v1.0.0
description: ...
parameters:
type: object
properties: {}Policy Manifest fileName should be the same one used in the policy definition file. version: v1
policies:
- name: Basic Auth
version: v1.0.0Directory StructureWhen unzipped, the policy source files should be in the following structure.
basic-auth/
└── v1.0.0/
├── basicauth.go
├── go.mod
└── README.md |
Beta Was this translation helpful? Give feedback.
-
|
Here are the files and format. Policy Definition FileThe name in the manifest file can be in any format in ASCII. name: Basic Auth
version: v1.0.0
description: ...
parameters:
type: object
properties: {}Policy Manifest fileThe name should be the same one used in the policy definition file. version: v1
policies:
- name: Basic Auth
version: v1.0.0From the apipctl command, when it is copying to the temp dir, it adds a FilePath section in the policy-manifest-lock.yaml file which is in the temp dir. This FilePath is used by the gateway builder to locate the policy source files. User's Project Dir (which commits to VCS)Lock file: version: v1/alpha1
policies:
- name: Basic Auth
version: v1.0.0
checksum: sha256:abc123...
source: hub
- name: Basic Auth
version: v1.0.1
checksum: sha256:abc123...
source: hub
- name: Basic Auth
version: v1.0.8
checksum: sha256:abc123...
source: hub
- name: My Custom Policy
version: v1.0.0
checksum: sha256:abc123...
source: localTemp DirThe directory names should not always be in the kebab-case format; it is an implementation detail in apipctl command. Lock file: version: v1/alpha1
policies:
- name: Basic Auth
version: v1.0.0
checksum: sha256:abc123...
source: hub
filePath: policies/basic-auth/v1.0.0
- name: Basic Auth
version: v1.0.1
checksum: sha256:abc123...
source: hub
filePath: policies/basic-auth/v1.0.1
- name: Basic Auth
version: v1.0.8
checksum: sha256:abc123...
source: hub
filePath: policies/basic-auth/v1.0.8
- name: My Custom Policy
version: v1.0.0
checksum: sha256:abc123...
source: local
filePath: policies/my-custom-policy/v1.0.0 |
Beta Was this translation helpful? Give feedback.
-
|
This is the flow we discussed cc: @renuka-fernando @piyumaldk Gateway Build Command FlowWhen the CLI gateway build command runs: Phase 1: Initialization
Phase 2: Caching
Phase 3: Prepare Workspace
Phase 4: Build
|
Beta Was this translation helpful? Give feedback.
-
@DakshithaS currently as per @piyumaldk the downloaded policy zip file contains the version folder inside it and inside that we have the files. Can we zip the content without that folder? |
Beta Was this translation helpful? Give feedback.
-
|
@piyumaldk Here is a sample expected You can test it out with the following raw commands. |
Beta Was this translation helpful? Give feedback.
-
|
As discussed with @malinthaprasan , we will enforce kebab-case (URL-friendly format) for the policy name. This policy name is the only identifier known to the Policy Engine. From a UI perspective, we will maintain a separate policy display name. This display name is not part of the policy definition, and the Policy Engine is not aware of it, it operates solely based on the policy name. The policy display name will be stored in the metadata.json file. When the Management Portal retrieves policy details from the Policy Hub, it can also obtain the corresponding policy display name. For custom policies, the policy display name and other UI-related metadata (which the Policy Engine does not need to know) will be stored in the Management Portal policy database. |
Beta Was this translation helpful? Give feedback.
-
APIPCTL CommandStep 1Sample Format Step 2Sample Format |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Building Gateway Image with Policies from Policy Hub using apipctl
apipctl Command
Format
Default values:
When
--offlineis set:Example
Run this command in a dir which contains the policy-manifest.yaml file.
This will output the following Docker images:
Policy.zip file name format
<policy-name>-v<policy-version>.zipHere policy-name and policy-version are in kebab-case format.
For example, BasicAuth v1.0.0 will be downloaded as
basic-auth-v1.0.0.zip.Unzipping this file will create a directory named
basic-auth/v1.0.0/containing the policy source files.Policy Cache
Location:
~/.apipctl/cache/policies/Structure:
Internals of the
apipctl gateway buildCommanddocker run --rm \ -v <temp-dir>:/workspace \ <gateway-builder-image>Policy Manifest file and lock file discussion: #473
Beta Was this translation helpful? Give feedback.
All reactions