# Fortify API Gateway Deployments with decK File Linting
Rick Spurgeon
Product Engineer, Kong
API gateways serve as the final checkpoint for your APIs. As such, gateway configuration is critical to ensuring that your APIs remain secure, available, and responsive. Ensuring that all changes to these configurations are intentional and follow your organization's best practices is key to maintaining a robust API gateway deployment.
[decK](https://docs.konghq.com/deck/latest/)decK 1.28 adds a brand new feature that allows you to natively validate your gateway configurations against custom rule sets. This helps ensure that best practices are followed and further fortifies your gateway deployments.
Linting is a common development process for validating code against a set of rules by looking for potential errors, stylistic issues, or deviations from standards. The code is flagged when rule violations are detected, allowing developers to intervene before potentially damaging changes make their way into production systems. Often, linting is performed within code editors and integrated development environments (IDEs). However, its integration into CI/CD pipelines is equally vital, to ensure that all changes — regardless of their source — adhere to established coding standards before merging into the codebase.
We have introduced linting capabilities directly into the decK command line tool, allowing you to perform a linting process for your API gateway configurations without introducing additional tools into your CI/CD pipelines.
## `deck file lint`
The `deck file lint` command at its core is a flexible JSON/YAML linter that allows you to build rules to validate any file in these formats.
There are a few key concepts to understand for linting with decK:
- **Rules** are named configurations that filter values from the incoming file and specify how to validate their contents.
- **Functions** accept the filtered values and perform a validation returning information when there are violations.
- **Rulesets** are collections of Rules.
Rules also provide the flexibility to define severity levels and output formats adding to the command’s versatility. Let’s look at an example usage of the command to validate a common Kong Gateway configuration value.
### Example
Kong Gateway services are defined in the `services` block in the decK file. Services support a number of configuration values including a protocol field which specifies the communication protocol used between the gateway and the upstream service. To ensure this traffic is secure, you may want to validate that only `https` protocols are used. Here is a sample Ruleset file containing a single Rule that accomplishes this.
## text
rules:
service-https-check:
description: "Ensure https usage in Kong GW Services"
given: $.services[*].protocol
severity: error
then:
function: pattern
functionOptions:
match: "^https$"
In the given field, a [JSONPath](http://jsonpath.com/)JSONPath selector is specified that reads the `protocol` field in every service under the `services` key from the incoming file. With each of those values, the `pattern` function is applied which evaluates the value against a regular expression pattern specified in the `match` field. In this example, we assert that the string value in the `protocol` field must match the string `https` exactly. Let’s assume the example Ruleset file is stored in a file named `ruleset.yaml`, and look at the `deck file lint` command in practice.
Assume you have the following decK declarative configuration file (`kong.yaml`) that defines a service and a route for a simple task tracking system:
Validating this configuration against the example ruleset results in the following violations:
## text
> deck file lint -s kong.yaml ruleset.yaml
Linting Violations: 1
Failures: 1
[error][7:15] Ensure https usage in Kong GW Services: `http` does not match the expression `^https$`
Modifying the declarative configuration as follows resolves this violation:
Notice that the command results in a `0` (Success) return code. In situations where violations are detected, a non-zero return code is emitted allowing you to abort automated processes and help prevent problematic configurations from leaking into your production codebase and systems.
Built for developers
We’ve taken the best parts of Terraform, deck, the AWS CLI, and more of your favorite tools and combined them into something that’s really special.
kongctl takes inspiration from the AWS CLI, with support for profiles. Profiles
If you've not heard of decK (our declarative configuration and drift detection tool for Kong Gateway ) before, now's a great time to get hands-on with it as we've just shipped decK v1.7.0 with a whole host of new goodies. Oh, and it's all open sou
There are two key concepts when a developer works with an API. The OpenAPI Spec describes how the API should work, and helps agents discover what is possible. The Collection and Requests help debug and verify how the endpoints currently function. P
Cameron HayGlass
# Kong API Gateway 3.16: From Debugging to Billing to Compliance
Two kinds of problems only show up once an API is already live. Something breaks, and a team needs visibility into one specific node right now — not after a redeploy. Or the right behavior for a request depends on who's calling it: a consumer's plan
Zongmin Li
# Why Your API Gateway Should Be Your Testing Environment
You invested in Kong Konnect. You centralized your API governance, locked down your routing, enforced your security policies, and gave your organization a single source of truth for every API in your estate. That work is done, and it is working. So
Haley Giuliano
# kongctl 1.0: A Declarative, AI-Native CLI for Kong Konnect
kongctl was built with the modern development stack in mind. Developers working in a terminal want the ability to query systems quickly to verify state, behaviors, and capabilities. Coding harnesses need well defined tools and accurate schemas for
Rick Spurgeon
# Scaling Kong Deployments with and without Databases
As the world's most popular API Gateway , Kong Gateway is flexible and can be adapted to various environments and deployment configurations. This flexibility means some time should be taken to make good architectural decisions for the use cases i
Built for developers
We’ve taken the best parts of Terraform, deck, the AWS CLI, and more of your favorite tools and combined them into something that’s really special.
kongctl takes inspiration from the AWS CLI, with support for profiles. Profiles
If you've not heard of decK (our declarative configuration and drift detection tool for Kong Gateway ) before, now's a great time to get hands-on with it as we've just shipped decK v1.7.0 with a whole host of new goodies. Oh, and it's all open sou
There are two key concepts when a developer works with an API. The OpenAPI Spec describes how the API should work, and helps agents discover what is possible. The Collection and Requests help debug and verify how the endpoints currently function. P
Cameron HayGlass
# Kong API Gateway 3.16: From Debugging to Billing to Compliance
Two kinds of problems only show up once an API is already live. Something breaks, and a team needs visibility into one specific node right now — not after a redeploy. Or the right behavior for a request depends on who's calling it: a consumer's plan
Zongmin Li
# Why Your API Gateway Should Be Your Testing Environment
You invested in Kong Konnect. You centralized your API governance, locked down your routing, enforced your security policies, and gave your organization a single source of truth for every API in your estate. That work is done, and it is working. So
Haley Giuliano
# kongctl 1.0: A Declarative, AI-Native CLI for Kong Konnect
kongctl was built with the modern development stack in mind. Developers working in a terminal want the ability to query systems quickly to verify state, behaviors, and capabilities. Coding harnesses need well defined tools and accurate schemas for
Rick Spurgeon
# Scaling Kong Deployments with and without Databases
As the world's most popular API Gateway , Kong Gateway is flexible and can be adapted to various environments and deployment configurations. This flexibility means some time should be taken to make good architectural decisions for the use cases i
Built for developers
We’ve taken the best parts of Terraform, deck, the AWS CLI, and more of your favorite tools and combined them into something that’s really special.
kongctl takes inspiration from the AWS CLI, with support for profiles. Profiles
If you've not heard of decK (our declarative configuration and drift detection tool for Kong Gateway ) before, now's a great time to get hands-on with it as we've just shipped decK v1.7.0 with a whole host of new goodies. Oh, and it's all open sou
There are two key concepts when a developer works with an API. The OpenAPI Spec describes how the API should work, and helps agents discover what is possible. The Collection and Requests help debug and verify how the endpoints currently function. P
Cameron HayGlass
# Kong API Gateway 3.16: From Debugging to Billing to Compliance
Two kinds of problems only show up once an API is already live. Something breaks, and a team needs visibility into one specific node right now — not after a redeploy. Or the right behavior for a request depends on who's calling it: a consumer's plan
Zongmin Li
# Why Your API Gateway Should Be Your Testing Environment
You invested in Kong Konnect. You centralized your API governance, locked down your routing, enforced your security policies, and gave your organization a single source of truth for every API in your estate. That work is done, and it is working. So
Haley Giuliano
# kongctl 1.0: A Declarative, AI-Native CLI for Kong Konnect
kongctl was built with the modern development stack in mind. Developers working in a terminal want the ability to query systems quickly to verify state, behaviors, and capabilities. Coding harnesses need well defined tools and accurate schemas for
Rick Spurgeon
# Scaling Kong Deployments with and without Databases
As the world's most popular API Gateway , Kong Gateway is flexible and can be adapted to various environments and deployment configurations. This flexibility means some time should be taken to make good architectural decisions for the use cases i
Ahmed Koshok
## Ready to see Kong in action?
Get a personalized walkthrough of Kong's platform tailored to your architecture, use cases, and scale requirements.