A lightweight and fast linter written in Go that helps DevOps and SRE teams enforce best practices across infrastructure-related files like Dockerfile, Makefile, .env, crontab, and systemd unit files.
It can be used as a CLI tool or as a pre-commit hook to automatically catch common misconfigurations, security issues, and anti-patterns before they hit your repository.
- Dockerfile: Detects usage of latest tag, missing USER directive, lack of HEALTHCHECK, and other common issues
- Makefile: Warns about missing .PHONY declarations, repeated targets, and unquoted variables
- Environment files: Finds weak passwords, duplicate keys, and syntax errors in .env files
- Crontab: Detects risky schedules, missing logging, and malformed time expressions
- Systemd units: Warns about missing Restart directives, unsafe paths, and insecure configurations
Download the latest binary from the releases page.
go install github.com/Gosayram/infra-linter@latestgit clone https://github.com/Gosayram/infra-linter.git
cd infra-linter
go build -o infra-linter ./cmd/infra-linter# Lint specific files
infra-linter Dockerfile .env Makefile
# Lint all supported files in current directory
infra-linter .
# Show help
infra-linter --help
# Show version
infra-linter --versionAdd to your .pre-commit-config.yaml:
repos:
- repo: https://github.com/Gosayram/infra-linter
rev: v1.0.0
hooks:
- id: infra-linter
name: Infrastructure Linter
entry: infra-linter
language: golang
files: \.(dockerfile|Dockerfile|env|makefile|Makefile|service|timer|socket)$
pass_filenames: trueThe linter checks for:
- Usage of
FROM image:latestwithout specific version tags - Missing
USERdirective (running as root) - Absence of
HEALTHCHECKfor long-running services - Inefficient layer caching patterns
- Security vulnerabilities in base images
The linter validates:
- Weak passwords in variables containing
password,secret, ortoken - Common weak values like
admin,123456,qwerty - Duplicate variable declarations
- Malformed syntax (incorrect spacing, quotes)
- Missing required environment variables
The linter detects:
- Missing
.PHONYdeclarations for non-file targets - Duplicate target names
- Unquoted variable references
- Inconsistent indentation (tabs vs spaces)
- Missing error handling in critical targets
The linter identifies:
- Risky scheduling patterns that might cause system overload
- Missing logging or output redirection
- Malformed time expressions
- Jobs running as privileged users without justification
The linter checks for:
- Missing
Restart=directives for services - Unsafe file paths or permissions
- Insecure service configurations
- Missing security hardening options
- Improper dependency declarations
Create a .infra-linter.yaml configuration file in your project root:
# Global settings
severity: warning
output_format: text
# File type specific settings
dockerfile:
allow_latest_tag: false
require_user: true
require_healthcheck: true
env:
check_weak_passwords: true
allowed_weak_patterns: []
require_quotes: false
makefile:
require_phony: true
check_duplicates: true
enforce_tabs: true
systemd:
require_restart: true
check_security: true
enforce_user: trueThe linter outputs messages in standard linter format:
[severity] file:line:column: message
[WARNING] Dockerfile:1:6: Using 'latest' tag is not recommended for production
[ERROR] .env:15:1: Duplicate environment variable 'DATABASE_PASSWORD'
[INFO] Makefile:23:1: Consider adding '.PHONY: clean' for non-file target
name: Infrastructure Lint
on: [push, pull_request]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: '1.21'
- name: Install infra-linter
run: go install github.com/Gosayram/infra-linter@latest
- name: Run linter
run: infra-linter .infra-lint:
image: golang:1.21
script:
- go install github.com/Gosayram/infra-linter@latest
- infra-linter .
rules:
- changes:
- "**/{Dockerfile,*.env,Makefile,*.service,*.timer}"We welcome contributions! Please see CONTRIBUTING.md for guidelines.
- Clone the repository
- Install Go 1.21 or later
- Run tests:
go test ./... - Build:
go build -o infra-linter ./cmd/infra-linter
This project is licensed under the MIT License - see the LICENSE file for details.
See IDEA.md for future plans and feature requests.
- Create an issue for bug reports
- Start a discussion for feature requests
- Check existing documentation