dns-sentinel 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dns_sentinel-0.1.0/.github/ISSUE_TEMPLATE/bug_report.yml +32 -0
- dns_sentinel-0.1.0/.github/ISSUE_TEMPLATE/feature_request.yml +22 -0
- dns_sentinel-0.1.0/.github/workflows/ci.yml +29 -0
- dns_sentinel-0.1.0/.github/workflows/publish.yml +26 -0
- dns_sentinel-0.1.0/.gitignore +14 -0
- dns_sentinel-0.1.0/CODE_OF_CONDUCT.md +7 -0
- dns_sentinel-0.1.0/COMMUNITY.md +34 -0
- dns_sentinel-0.1.0/CONTRIBUTING.md +19 -0
- dns_sentinel-0.1.0/LICENSE +17 -0
- dns_sentinel-0.1.0/PKG-INFO +102 -0
- dns_sentinel-0.1.0/README.md +71 -0
- dns_sentinel-0.1.0/ROADMAP.md +29 -0
- dns_sentinel-0.1.0/SECURITY.md +11 -0
- dns_sentinel-0.1.0/docs/RELEASING.md +23 -0
- dns_sentinel-0.1.0/pyproject.toml +58 -0
- dns_sentinel-0.1.0/src/dns_sentinel/__init__.py +6 -0
- dns_sentinel-0.1.0/src/dns_sentinel/auditor.py +422 -0
- dns_sentinel-0.1.0/src/dns_sentinel/cli.py +45 -0
- dns_sentinel-0.1.0/tests/test_auditor.py +160 -0
- dns_sentinel-0.1.0/tests/test_cli.py +32 -0
- dns_sentinel-0.1.0/tests/test_integration.py +20 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
name: Bug report
|
|
2
|
+
description: Report a reproducible incorrect result or crash
|
|
3
|
+
labels: [bug]
|
|
4
|
+
body:
|
|
5
|
+
- type: markdown
|
|
6
|
+
attributes:
|
|
7
|
+
value: Do not include secrets or private DNS data. Please verify the issue against the documented MVP limits.
|
|
8
|
+
- type: input
|
|
9
|
+
id: version
|
|
10
|
+
attributes:
|
|
11
|
+
label: DNS Sentinel version
|
|
12
|
+
validations:
|
|
13
|
+
required: true
|
|
14
|
+
- type: textarea
|
|
15
|
+
id: expected
|
|
16
|
+
attributes:
|
|
17
|
+
label: Expected result and evidence
|
|
18
|
+
description: Include relevant DNS output with sensitive values redacted and standards references if applicable.
|
|
19
|
+
validations:
|
|
20
|
+
required: true
|
|
21
|
+
- type: textarea
|
|
22
|
+
id: actual
|
|
23
|
+
attributes:
|
|
24
|
+
label: Actual result
|
|
25
|
+
validations:
|
|
26
|
+
required: true
|
|
27
|
+
- type: textarea
|
|
28
|
+
id: reproduce
|
|
29
|
+
attributes:
|
|
30
|
+
label: Reproduction steps
|
|
31
|
+
validations:
|
|
32
|
+
required: true
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
name: Feature request
|
|
2
|
+
description: Propose a focused, standards-backed improvement
|
|
3
|
+
labels: [enhancement]
|
|
4
|
+
body:
|
|
5
|
+
- type: textarea
|
|
6
|
+
id: problem
|
|
7
|
+
attributes:
|
|
8
|
+
label: Problem and users affected
|
|
9
|
+
validations:
|
|
10
|
+
required: true
|
|
11
|
+
- type: input
|
|
12
|
+
id: evidence
|
|
13
|
+
attributes:
|
|
14
|
+
label: Relevant RFC or documentation
|
|
15
|
+
validations:
|
|
16
|
+
required: true
|
|
17
|
+
- type: textarea
|
|
18
|
+
id: acceptance
|
|
19
|
+
attributes:
|
|
20
|
+
label: Expected behavior and test cases
|
|
21
|
+
validations:
|
|
22
|
+
required: true
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
workflow_dispatch:
|
|
8
|
+
|
|
9
|
+
permissions:
|
|
10
|
+
contents: read
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
checks:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
strategy:
|
|
16
|
+
fail-fast: false
|
|
17
|
+
matrix:
|
|
18
|
+
python-version: ["3.10", "3.11", "3.12"]
|
|
19
|
+
steps:
|
|
20
|
+
- uses: actions/checkout@v4
|
|
21
|
+
- uses: actions/setup-python@v5
|
|
22
|
+
with:
|
|
23
|
+
python-version: ${{ matrix.python-version }}
|
|
24
|
+
cache: pip
|
|
25
|
+
- run: python -m pip install -e '.[dev]'
|
|
26
|
+
- run: pytest --cov=dns_sentinel --cov-report=term-missing
|
|
27
|
+
- run: ruff check .
|
|
28
|
+
- run: mypy
|
|
29
|
+
- run: python -m build
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
|
|
7
|
+
permissions:
|
|
8
|
+
contents: read
|
|
9
|
+
id-token: write
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
publish:
|
|
13
|
+
name: Build and publish
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
environment:
|
|
16
|
+
name: pypi
|
|
17
|
+
url: https://pypi.org/p/dns-sentinel
|
|
18
|
+
steps:
|
|
19
|
+
- uses: actions/checkout@v4
|
|
20
|
+
- uses: actions/setup-python@v5
|
|
21
|
+
with:
|
|
22
|
+
python-version: "3.12"
|
|
23
|
+
- run: python -m pip install --upgrade build
|
|
24
|
+
- run: python -m build
|
|
25
|
+
- name: Publish package to PyPI
|
|
26
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
We are committed to a respectful, welcoming community. Participants should be considerate, assume good faith, give constructive feedback, and focus criticism on ideas and code. Harassment, discrimination, intimidation, personal attacks, and unwanted sexual attention are not acceptable.
|
|
4
|
+
|
|
5
|
+
Maintainers may edit or remove contributions that violate this code and may restrict participation when necessary. Report incidents privately to the repository maintainers. Please include enough detail to investigate; reports will be handled as confidentially as practical.
|
|
6
|
+
|
|
7
|
+
This project adapts the Contributor Covenant, version 2.1. See https://www.contributor-covenant.org/version/2/1/code_of_conduct/ for the full text and attribution.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Community growth plan
|
|
2
|
+
|
|
3
|
+
The long-term aspiration is 20 unique external contributors with merged pull requests in a rolling 12-month period. It is an outcome, not a promise or a qualification claim. Contributions must come from genuine, independent people; no alternate accounts, paid low-quality PRs, artificial stars, or fabricated usage will be counted.
|
|
4
|
+
|
|
5
|
+
## Make useful work visible
|
|
6
|
+
|
|
7
|
+
- Publish a tested release and a short demo showing what the tool can and cannot conclude.
|
|
8
|
+
- Share standards-backed findings and reproducible bug reports with DNS, Python, security engineering, and open-source communities. Follow each community's self-promotion rules; do not spam.
|
|
9
|
+
- Ask a small number of practitioners to review specific protocol checks, rather than asking broadly for stars.
|
|
10
|
+
- Write short notes when a standards nuance changes a finding, with test vectors and links to the relevant RFC.
|
|
11
|
+
|
|
12
|
+
## Give newcomers a reliable first experience
|
|
13
|
+
|
|
14
|
+
- Keep a public `good first issue` queue with exact expected behavior, pointers to code, and acceptance tests. Create issues only after confirming they are real and in scope.
|
|
15
|
+
- Keep issues small enough to complete in a few hours; examples include a standards test vector, clearer error wording, or one isolated parser edge case.
|
|
16
|
+
- Maintain a contributor setup that works from a clean clone and CI that runs the same checks.
|
|
17
|
+
- Acknowledge new reports promptly, explain decisions respectfully, and credit accepted contributions in release notes.
|
|
18
|
+
- Do not label work `good first issue` if it needs undisclosed design work or maintainer-only access.
|
|
19
|
+
|
|
20
|
+
## Build trust and retain contributors
|
|
21
|
+
|
|
22
|
+
- Prefer RFC citations, captured evidence, and regression tests over popularity claims.
|
|
23
|
+
- Publish release notes, known limitations, and response expectations. If maintainer capacity changes, update those expectations openly.
|
|
24
|
+
- Review external pull requests for correctness and scope; do not merge PRs just to increase a count.
|
|
25
|
+
- Track only public, verifiable project signals: unique outside contributors whose PRs actually merged, time to first maintainer response, and repeat contributors. Review the rolling 12-month contributor count quarterly.
|
|
26
|
+
- Invite contributors to choose work; do not promise jobs, credentials, or qualification outcomes.
|
|
27
|
+
|
|
28
|
+
## First 90 days after publishing
|
|
29
|
+
|
|
30
|
+
1. Confirm install, CLI, tests, and CI from a clean clone; address issues before promotion.
|
|
31
|
+
2. Ask several DNS/mail practitioners for technical review and incorporate feedback with tests.
|
|
32
|
+
3. Open a small set of real issues from documented limitations: SPF edge cases, DMARC URI handling, CAA properties, and resolver test fixtures.
|
|
33
|
+
4. Share one practical tutorial and one short demo in appropriate communities, following their rules.
|
|
34
|
+
5. Review engagement monthly. If there are no external contributions, improve utility and onboarding instead of manufacturing activity.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
Thanks for helping make DNS Sentinel accurate and useful. Contributions should be small, tested, and clear about their limits.
|
|
4
|
+
|
|
5
|
+
## Before opening a pull request
|
|
6
|
+
|
|
7
|
+
1. Search existing issues and explain the use case or standards requirement.
|
|
8
|
+
2. For protocol behavior, cite the relevant RFC or authoritative documentation.
|
|
9
|
+
3. Add deterministic tests. Unit tests must not depend on public DNS or a real domain.
|
|
10
|
+
4. Run `pytest`, `ruff check .`, `mypy`, and `python -m build` locally.
|
|
11
|
+
5. Describe behavior changes and any remaining limits in the pull request.
|
|
12
|
+
|
|
13
|
+
## Scope and review
|
|
14
|
+
|
|
15
|
+
Avoid broad rewrites and new dependencies without a concrete need. Never add active probing, credential collection, or DNS mutations without prior discussion. A passing CI run does not establish protocol correctness; reviewers will check claims against evidence and standards. Maintainers aim to acknowledge issues within seven days and review pull requests within fourteen days, subject to availability; these are goals, not guarantees.
|
|
16
|
+
|
|
17
|
+
## First contributions
|
|
18
|
+
|
|
19
|
+
Look for issues labeled `good first issue` and ask for clarification before spending substantial time. A contribution is considered merged only when accepted into the default branch. The project does not promise acceptance or any external qualification outcome.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 DNS Sentinel contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: dns-sentinel
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A practical, read-only DNS configuration security auditor
|
|
5
|
+
Project-URL: Homepage, https://github.com/kkevadiya54/dns-sentinel
|
|
6
|
+
Project-URL: Repository, https://github.com/kkevadiya54/dns-sentinel
|
|
7
|
+
Project-URL: Issues, https://github.com/kkevadiya54/dns-sentinel/issues
|
|
8
|
+
Author: DNS Sentinel contributors
|
|
9
|
+
License: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: auditing,dmarc,dns,dnssec,security,spf
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Environment :: Console
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Topic :: Internet :: Name Service (DNS)
|
|
22
|
+
Requires-Python: >=3.10
|
|
23
|
+
Requires-Dist: dnspython<3,>=2.6
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: build>=1.2; extra == 'dev'
|
|
26
|
+
Requires-Dist: mypy>=1.11; extra == 'dev'
|
|
27
|
+
Requires-Dist: pytest-cov>=5; extra == 'dev'
|
|
28
|
+
Requires-Dist: pytest>=8; extra == 'dev'
|
|
29
|
+
Requires-Dist: ruff>=0.6; extra == 'dev'
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
|
|
32
|
+
# DNS Sentinel
|
|
33
|
+
|
|
34
|
+
DNS Sentinel is a read-only command-line tool and Python library for a first-pass review of public DNS security configuration. It checks SPF, DMARC, CAA, MX, nameserver count, and DNSSEC record presence. It is an early MVP: results are evidence-based hints, not a compliance certificate or a substitute for a mail/DNS specialist.
|
|
35
|
+
|
|
36
|
+
## Install and run
|
|
37
|
+
|
|
38
|
+
Requires Python 3.10 or newer.
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
git clone https://github.com/kkevadiya54/dns-sentinel.git
|
|
42
|
+
cd dns-sentinel
|
|
43
|
+
python -m pip install .
|
|
44
|
+
dns-sentinel example.com
|
|
45
|
+
dns-sentinel example.com --json
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
The first PyPI release is prepared but pending PyPI Trusted Publishing setup; until it is released, install from the repository as shown above.
|
|
49
|
+
|
|
50
|
+
Exit status is `0` when no error-severity findings exist, `1` when an error-severity finding exists, and `2` when input or runtime setup prevents an audit. Warnings can indicate missing controls or incomplete answers. Network timeouts are reported per check and do not discard other results.
|
|
51
|
+
|
|
52
|
+
Use only for domains you are authorized to assess. The tool sends ordinary DNS queries to the system-configured recursive resolver; it does not scan hosts, change DNS, or send email.
|
|
53
|
+
|
|
54
|
+
## What checks mean
|
|
55
|
+
|
|
56
|
+
| Check | MVP behavior | Not claimed |
|
|
57
|
+
| --- | --- | --- |
|
|
58
|
+
| SPF | Detects zero/multiple policies and performs basic token sanity checks | Full RFC 7208 evaluation, include/redirect expansion, DNS lookup limits, or authorization outcome |
|
|
59
|
+
| DMARC | Requires one `_dmarc` TXT policy and validates version, policy, duplicate tags, `pct`, and basic `rua` syntax | Full RFC 9989 semantics, organizational-domain discovery, or report processing |
|
|
60
|
+
| CAA | Checks returned CAA tag names and flags | Complete CAA tree-walk inheritance, issuer authorization semantics, or certificate issuance outcome |
|
|
61
|
+
| MX | Checks preference/exchange shape, duplicate targets, and RFC 7505 null MX | Whether each mail host is reachable or correctly configured |
|
|
62
|
+
| NS | Counts distinct returned NS targets | Independent operators, networks, geographic diversity, or authoritative delegation consistency |
|
|
63
|
+
| DNSSEC | Reports whether DNSKEY and DS records were observed at the queried name | **Cryptographic validation.** The resolver may or may not validate; this tool does not inspect signatures or establish a chain of trust. |
|
|
64
|
+
|
|
65
|
+
DNS negative answers and resolver failures are different. A timeout, SERVFAIL-like nameserver failure, or local resolver problem produces an `unknown`/warning result where relevant; it is not reported as proof that a record is absent. DNSSEC checks are strictly record-presence checks.
|
|
66
|
+
|
|
67
|
+
## Python API
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
from dns_sentinel import Auditor
|
|
71
|
+
|
|
72
|
+
report = Auditor(timeout=2, lifetime=5).audit("example.com")
|
|
73
|
+
for finding in report.findings:
|
|
74
|
+
print(finding.check, finding.status, finding.message)
|
|
75
|
+
print(report.to_dict())
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Development
|
|
79
|
+
|
|
80
|
+
```sh
|
|
81
|
+
python -m venv .venv
|
|
82
|
+
. .venv/bin/activate
|
|
83
|
+
python -m pip install -e '.[dev]'
|
|
84
|
+
pytest --cov=dns_sentinel --cov-report=term-missing
|
|
85
|
+
ruff check .
|
|
86
|
+
mypy
|
|
87
|
+
python -m build
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Integration checks can query a domain you control, for example `dns-sentinel example.com`; the unit suite uses deterministic resolver fakes and does not depend on public DNS.
|
|
91
|
+
|
|
92
|
+
## Contributing
|
|
93
|
+
|
|
94
|
+
Read [CONTRIBUTING.md](CONTRIBUTING.md), the [Code of Conduct](CODE_OF_CONDUCT.md), [SECURITY.md](SECURITY.md), and [COMMUNITY.md](COMMUNITY.md). Small reproducible fixes, standards-backed tests, documentation improvements, and carefully scoped record checks are welcome. Please do not claim a check validates more than it does.
|
|
95
|
+
|
|
96
|
+
## Project status
|
|
97
|
+
|
|
98
|
+
Alpha software. No external contributors, package downloads, adoption, or certifications are claimed. See [ROADMAP.md](ROADMAP.md) for the staged plan and honest limits.
|
|
99
|
+
|
|
100
|
+
## License
|
|
101
|
+
|
|
102
|
+
MIT; see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# DNS Sentinel
|
|
2
|
+
|
|
3
|
+
DNS Sentinel is a read-only command-line tool and Python library for a first-pass review of public DNS security configuration. It checks SPF, DMARC, CAA, MX, nameserver count, and DNSSEC record presence. It is an early MVP: results are evidence-based hints, not a compliance certificate or a substitute for a mail/DNS specialist.
|
|
4
|
+
|
|
5
|
+
## Install and run
|
|
6
|
+
|
|
7
|
+
Requires Python 3.10 or newer.
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
git clone https://github.com/kkevadiya54/dns-sentinel.git
|
|
11
|
+
cd dns-sentinel
|
|
12
|
+
python -m pip install .
|
|
13
|
+
dns-sentinel example.com
|
|
14
|
+
dns-sentinel example.com --json
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
The first PyPI release is prepared but pending PyPI Trusted Publishing setup; until it is released, install from the repository as shown above.
|
|
18
|
+
|
|
19
|
+
Exit status is `0` when no error-severity findings exist, `1` when an error-severity finding exists, and `2` when input or runtime setup prevents an audit. Warnings can indicate missing controls or incomplete answers. Network timeouts are reported per check and do not discard other results.
|
|
20
|
+
|
|
21
|
+
Use only for domains you are authorized to assess. The tool sends ordinary DNS queries to the system-configured recursive resolver; it does not scan hosts, change DNS, or send email.
|
|
22
|
+
|
|
23
|
+
## What checks mean
|
|
24
|
+
|
|
25
|
+
| Check | MVP behavior | Not claimed |
|
|
26
|
+
| --- | --- | --- |
|
|
27
|
+
| SPF | Detects zero/multiple policies and performs basic token sanity checks | Full RFC 7208 evaluation, include/redirect expansion, DNS lookup limits, or authorization outcome |
|
|
28
|
+
| DMARC | Requires one `_dmarc` TXT policy and validates version, policy, duplicate tags, `pct`, and basic `rua` syntax | Full RFC 9989 semantics, organizational-domain discovery, or report processing |
|
|
29
|
+
| CAA | Checks returned CAA tag names and flags | Complete CAA tree-walk inheritance, issuer authorization semantics, or certificate issuance outcome |
|
|
30
|
+
| MX | Checks preference/exchange shape, duplicate targets, and RFC 7505 null MX | Whether each mail host is reachable or correctly configured |
|
|
31
|
+
| NS | Counts distinct returned NS targets | Independent operators, networks, geographic diversity, or authoritative delegation consistency |
|
|
32
|
+
| DNSSEC | Reports whether DNSKEY and DS records were observed at the queried name | **Cryptographic validation.** The resolver may or may not validate; this tool does not inspect signatures or establish a chain of trust. |
|
|
33
|
+
|
|
34
|
+
DNS negative answers and resolver failures are different. A timeout, SERVFAIL-like nameserver failure, or local resolver problem produces an `unknown`/warning result where relevant; it is not reported as proof that a record is absent. DNSSEC checks are strictly record-presence checks.
|
|
35
|
+
|
|
36
|
+
## Python API
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
from dns_sentinel import Auditor
|
|
40
|
+
|
|
41
|
+
report = Auditor(timeout=2, lifetime=5).audit("example.com")
|
|
42
|
+
for finding in report.findings:
|
|
43
|
+
print(finding.check, finding.status, finding.message)
|
|
44
|
+
print(report.to_dict())
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Development
|
|
48
|
+
|
|
49
|
+
```sh
|
|
50
|
+
python -m venv .venv
|
|
51
|
+
. .venv/bin/activate
|
|
52
|
+
python -m pip install -e '.[dev]'
|
|
53
|
+
pytest --cov=dns_sentinel --cov-report=term-missing
|
|
54
|
+
ruff check .
|
|
55
|
+
mypy
|
|
56
|
+
python -m build
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Integration checks can query a domain you control, for example `dns-sentinel example.com`; the unit suite uses deterministic resolver fakes and does not depend on public DNS.
|
|
60
|
+
|
|
61
|
+
## Contributing
|
|
62
|
+
|
|
63
|
+
Read [CONTRIBUTING.md](CONTRIBUTING.md), the [Code of Conduct](CODE_OF_CONDUCT.md), [SECURITY.md](SECURITY.md), and [COMMUNITY.md](COMMUNITY.md). Small reproducible fixes, standards-backed tests, documentation improvements, and carefully scoped record checks are welcome. Please do not claim a check validates more than it does.
|
|
64
|
+
|
|
65
|
+
## Project status
|
|
66
|
+
|
|
67
|
+
Alpha software. No external contributors, package downloads, adoption, or certifications are claimed. See [ROADMAP.md](ROADMAP.md) for the staged plan and honest limits.
|
|
68
|
+
|
|
69
|
+
## License
|
|
70
|
+
|
|
71
|
+
MIT; see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Roadmap
|
|
2
|
+
|
|
3
|
+
This roadmap describes intent, not promises. Work is prioritized by correctness, reproducibility, and maintainability; timelines depend on contributors and review capacity.
|
|
4
|
+
|
|
5
|
+
## MVP (0.1.x)
|
|
6
|
+
|
|
7
|
+
- [x] Read-only CLI and Python API
|
|
8
|
+
- [x] Per-query DNS failure handling and machine-readable JSON
|
|
9
|
+
- [x] Basic SPF, DMARC, CAA, MX, NS, and DNSSEC record-presence checks
|
|
10
|
+
- [x] Deterministic unit tests, packaging, and CI foundations
|
|
11
|
+
- [ ] Independent review against relevant RFCs, including RFC 9989, before stable release
|
|
12
|
+
|
|
13
|
+
## Next (0.2)
|
|
14
|
+
|
|
15
|
+
- RFC-driven test vectors and stronger record parsing, especially SPF mechanisms and CAA properties
|
|
16
|
+
- Explicit resolver configuration and reproducible integration test harness
|
|
17
|
+
- Optional authoritative-delegation consistency checks
|
|
18
|
+
- Output schema versioning and stable severity/status definitions
|
|
19
|
+
|
|
20
|
+
## Later (0.3+)
|
|
21
|
+
|
|
22
|
+
- Optional, clearly separated cryptographic DNSSEC validation using a vetted validator/library
|
|
23
|
+
- Mail DNS checks for DKIM selectors only when explicitly supplied by the user
|
|
24
|
+
- Baseline comparison and monitoring integrations, only with transparent privacy controls
|
|
25
|
+
- Release automation, signed artifacts, provenance, and OpenSSF scorecard review
|
|
26
|
+
|
|
27
|
+
## Out of scope until reviewed
|
|
28
|
+
|
|
29
|
+
Full SPF policy evaluation is easy to get wrong and can trigger DNS amplification/lookup-limit issues. Complete DNSSEC validation requires correct trust-anchor and chain handling. These will not be implied by superficial record checks. No target contributor counts, stars, downloads, or qualification results are guaranteed or manufactured.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Security policy
|
|
2
|
+
|
|
3
|
+
## Reporting a vulnerability
|
|
4
|
+
|
|
5
|
+
Do not report security vulnerabilities in public issues. Use GitHub's private vulnerability reporting for the repository if enabled. If it is unavailable, contact the maintainer through the email listed on the GitHub profile. Include affected version, impact, and a minimal reproduction. Please allow reasonable time for a fix before public disclosure.
|
|
6
|
+
|
|
7
|
+
DNS Sentinel is a read-only auditor and currently makes DNS queries through the system resolver. It does not provide a guarantee that a domain is safe, correctly configured, or cryptographically validated. Do not send secrets or personal data in audit output or issue reports.
|
|
8
|
+
|
|
9
|
+
## Supported versions
|
|
10
|
+
|
|
11
|
+
Only the latest release is supported during this alpha stage.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Releasing
|
|
2
|
+
|
|
3
|
+
The package is not published to PyPI yet. The GitHub release workflow uses PyPI Trusted Publishing, so no long-lived PyPI token is stored in GitHub.
|
|
4
|
+
|
|
5
|
+
## One-time PyPI setup
|
|
6
|
+
|
|
7
|
+
1. Sign in to the PyPI account that will own `dns-sentinel` (or create that account).
|
|
8
|
+
2. In PyPI's Trusted Publishers settings, add a GitHub Actions publisher with:
|
|
9
|
+
- Owner: `kkevadiya54`
|
|
10
|
+
- Repository: `dns-sentinel`
|
|
11
|
+
- Workflow: `publish.yml`
|
|
12
|
+
- Environment: `pypi`
|
|
13
|
+
3. Keep the PyPI account's recovery methods current. Do not put an API token in a repository secret for this workflow.
|
|
14
|
+
|
|
15
|
+
## Release a version
|
|
16
|
+
|
|
17
|
+
1. Update the project version in `pyproject.toml` and the changelog/release notes.
|
|
18
|
+
2. Run unit tests, lint, type checks, integration tests where network access is available, and `python -m build`.
|
|
19
|
+
3. Merge the release change through a pull request and wait for CI.
|
|
20
|
+
4. Create and publish a GitHub release for the matching version tag (for example `v0.1.0`).
|
|
21
|
+
5. Confirm the `Publish to PyPI` workflow succeeded and verify the installed distribution from a clean environment.
|
|
22
|
+
|
|
23
|
+
PyPI releases are public and cannot be silently replaced. Publish only after reviewing the built artifacts and release notes. The first release remains pending until the account owner completes the PyPI publisher setup.
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.25"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "dns-sentinel"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "A practical, read-only DNS configuration security auditor"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = { text = "MIT" }
|
|
12
|
+
authors = [{ name = "DNS Sentinel contributors" }]
|
|
13
|
+
keywords = ["dns", "security", "spf", "dmarc", "dnssec", "auditing"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 3 - Alpha",
|
|
16
|
+
"Environment :: Console",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"License :: OSI Approved :: MIT License",
|
|
19
|
+
"Operating System :: OS Independent",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3.10",
|
|
22
|
+
"Programming Language :: Python :: 3.11",
|
|
23
|
+
"Programming Language :: Python :: 3.12",
|
|
24
|
+
"Topic :: Internet :: Name Service (DNS)",
|
|
25
|
+
]
|
|
26
|
+
dependencies = ["dnspython>=2.6,<3"]
|
|
27
|
+
|
|
28
|
+
[project.urls]
|
|
29
|
+
Homepage = "https://github.com/kkevadiya54/dns-sentinel"
|
|
30
|
+
Repository = "https://github.com/kkevadiya54/dns-sentinel"
|
|
31
|
+
Issues = "https://github.com/kkevadiya54/dns-sentinel/issues"
|
|
32
|
+
|
|
33
|
+
[project.optional-dependencies]
|
|
34
|
+
dev = ["pytest>=8", "pytest-cov>=5", "ruff>=0.6", "mypy>=1.11", "build>=1.2"]
|
|
35
|
+
|
|
36
|
+
[project.scripts]
|
|
37
|
+
dns-sentinel = "dns_sentinel.cli:main"
|
|
38
|
+
|
|
39
|
+
[tool.hatch.build.targets.wheel]
|
|
40
|
+
packages = ["src/dns_sentinel"]
|
|
41
|
+
|
|
42
|
+
[tool.pytest.ini_options]
|
|
43
|
+
testpaths = ["tests"]
|
|
44
|
+
addopts = "-ra --strict-markers -m 'not integration'"
|
|
45
|
+
markers = ["integration: requires external DNS resolution"]
|
|
46
|
+
|
|
47
|
+
[tool.ruff]
|
|
48
|
+
line-length = 100
|
|
49
|
+
target-version = "py310"
|
|
50
|
+
|
|
51
|
+
[tool.ruff.lint]
|
|
52
|
+
select = ["E", "F", "I", "UP", "B"]
|
|
53
|
+
|
|
54
|
+
[tool.mypy]
|
|
55
|
+
python_version = "3.10"
|
|
56
|
+
strict = true
|
|
57
|
+
mypy_path = "src"
|
|
58
|
+
packages = ["dns_sentinel"]
|
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
"""DNS record checks with explicit limits and per-query failure isolation."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import ipaddress
|
|
6
|
+
import re
|
|
7
|
+
from dataclasses import asdict, dataclass
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
import dns.exception
|
|
11
|
+
import dns.resolver
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@dataclass(frozen=True, slots=True)
|
|
15
|
+
class Finding:
|
|
16
|
+
check: str
|
|
17
|
+
status: str
|
|
18
|
+
severity: str
|
|
19
|
+
message: str
|
|
20
|
+
evidence: tuple[str, ...] = ()
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@dataclass(frozen=True, slots=True)
|
|
24
|
+
class Report:
|
|
25
|
+
domain: str
|
|
26
|
+
findings: tuple[Finding, ...]
|
|
27
|
+
|
|
28
|
+
def to_dict(self) -> dict[str, Any]:
|
|
29
|
+
return {"domain": self.domain, "findings": [asdict(item) for item in self.findings]}
|
|
30
|
+
|
|
31
|
+
@property
|
|
32
|
+
def passed(self) -> bool:
|
|
33
|
+
return not any(f.severity == "error" for f in self.findings)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def normalize_domain(domain: str) -> str:
|
|
37
|
+
"""Validate and normalize a DNS hostname; reject URL/path inputs and IP literals."""
|
|
38
|
+
value = domain.strip().rstrip(".")
|
|
39
|
+
if not value or any(char in value for char in "/:@?#"):
|
|
40
|
+
raise ValueError("Provide a DNS domain name, not a URL or address.")
|
|
41
|
+
try:
|
|
42
|
+
ascii_name = value.encode("idna").decode("ascii").lower()
|
|
43
|
+
except UnicodeError as exc:
|
|
44
|
+
raise ValueError("Domain is not valid IDNA.") from exc
|
|
45
|
+
if len(ascii_name) > 253 or "." not in ascii_name:
|
|
46
|
+
raise ValueError("Provide a fully qualified domain name (for example, example.com).")
|
|
47
|
+
labels = ascii_name.split(".")
|
|
48
|
+
if any(
|
|
49
|
+
not label or len(label) > 63 or not re.fullmatch(r"[a-z0-9](?:[a-z0-9-]*[a-z0-9])?", label)
|
|
50
|
+
for label in labels
|
|
51
|
+
):
|
|
52
|
+
raise ValueError("Domain contains an invalid DNS label.")
|
|
53
|
+
return ascii_name
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class Auditor:
|
|
57
|
+
"""Read-only DNS auditor. DNSSEC results report records only, never cryptographic validity."""
|
|
58
|
+
|
|
59
|
+
def __init__(self, timeout: float = 2.0, lifetime: float = 5.0, resolver: Any = None):
|
|
60
|
+
if timeout <= 0 or lifetime <= 0:
|
|
61
|
+
raise ValueError("DNS timeouts must be positive.")
|
|
62
|
+
self.resolver = resolver or dns.resolver.Resolver()
|
|
63
|
+
self.resolver.timeout = timeout
|
|
64
|
+
self.resolver.lifetime = lifetime
|
|
65
|
+
|
|
66
|
+
def _query(self, name: str, kind: str) -> tuple[list[str], str | None]:
|
|
67
|
+
try:
|
|
68
|
+
answer = self.resolver.resolve(name, kind, search=False, raise_on_no_answer=False)
|
|
69
|
+
if answer.rrset is None:
|
|
70
|
+
return [], "no records"
|
|
71
|
+
return [item if isinstance(item, str) else item.to_text() for item in answer], None
|
|
72
|
+
except dns.resolver.NXDOMAIN:
|
|
73
|
+
return [], "name does not exist"
|
|
74
|
+
except dns.resolver.NoAnswer:
|
|
75
|
+
return [], "no records"
|
|
76
|
+
except (dns.resolver.LifetimeTimeout, dns.exception.Timeout):
|
|
77
|
+
return [], "DNS query timed out"
|
|
78
|
+
except dns.resolver.NoNameservers:
|
|
79
|
+
return [], "all configured name servers failed"
|
|
80
|
+
except (dns.resolver.NoResolverConfiguration, OSError) as exc:
|
|
81
|
+
return [], f"DNS resolver unavailable: {exc}"
|
|
82
|
+
except dns.exception.DNSException as exc:
|
|
83
|
+
return [], f"DNS query failed: {exc.__class__.__name__}"
|
|
84
|
+
|
|
85
|
+
def audit(self, domain: str) -> Report:
|
|
86
|
+
name = normalize_domain(domain)
|
|
87
|
+
findings = (
|
|
88
|
+
self._check_spf(name),
|
|
89
|
+
self._check_dmarc(name),
|
|
90
|
+
self._check_caa(name),
|
|
91
|
+
self._check_mx(name),
|
|
92
|
+
self._check_ns(name),
|
|
93
|
+
self._check_dnssec_presence(name),
|
|
94
|
+
)
|
|
95
|
+
return Report(name, findings)
|
|
96
|
+
|
|
97
|
+
def _txt(self, name: str, check: str) -> tuple[list[str], Finding | None]:
|
|
98
|
+
rows, error = self._query(name, "TXT")
|
|
99
|
+
if error and error != "no records":
|
|
100
|
+
return [], Finding(check, "error", "warning", f"Could not query TXT records: {error}")
|
|
101
|
+
# DNS TXT character-strings concatenate without separators per RFC 1035.
|
|
102
|
+
return [
|
|
103
|
+
"".join(re.findall(r'"((?:[^"\\]|\\.)*)"', row)).replace(r"\"", '"') for row in rows
|
|
104
|
+
], None
|
|
105
|
+
|
|
106
|
+
def _check_spf(self, name: str) -> Finding:
|
|
107
|
+
records, issue = self._txt(name, "spf")
|
|
108
|
+
if issue:
|
|
109
|
+
return issue
|
|
110
|
+
spf = [r for r in records if r.lower().startswith("v=spf1")]
|
|
111
|
+
if not spf:
|
|
112
|
+
return Finding("spf", "fail", "warning", "No SPF policy was found.")
|
|
113
|
+
if len(spf) > 1:
|
|
114
|
+
return Finding(
|
|
115
|
+
"spf",
|
|
116
|
+
"fail",
|
|
117
|
+
"error",
|
|
118
|
+
"Multiple SPF policies exist; receivers cannot select one.",
|
|
119
|
+
tuple(spf),
|
|
120
|
+
)
|
|
121
|
+
tokens = spf[0].lower().split()
|
|
122
|
+
if tokens[0] != "v=spf1" or len(tokens) < 2:
|
|
123
|
+
return Finding("spf", "fail", "error", "SPF policy is empty or malformed.", tuple(spf))
|
|
124
|
+
mechanisms = [t.lstrip("+-~?") for t in tokens[1:]]
|
|
125
|
+
seen_modifiers: set[str] = set()
|
|
126
|
+
for mechanism in mechanisms:
|
|
127
|
+
if mechanism.startswith(("redirect=", "exp=")):
|
|
128
|
+
key, value = mechanism.split("=", 1)
|
|
129
|
+
if key in seen_modifiers or not value or "." not in value:
|
|
130
|
+
return Finding(
|
|
131
|
+
"spf",
|
|
132
|
+
"fail",
|
|
133
|
+
"error",
|
|
134
|
+
"SPF modifier is duplicated or malformed.",
|
|
135
|
+
tuple(spf),
|
|
136
|
+
)
|
|
137
|
+
seen_modifiers.add(key)
|
|
138
|
+
continue
|
|
139
|
+
kind, separator, argument = mechanism.partition(":")
|
|
140
|
+
kind = kind.split("/", 1)[0]
|
|
141
|
+
if kind == "all" and (separator or "/" in mechanism):
|
|
142
|
+
return Finding(
|
|
143
|
+
"spf",
|
|
144
|
+
"fail",
|
|
145
|
+
"error",
|
|
146
|
+
"SPF 'all' mechanism cannot take an argument.",
|
|
147
|
+
tuple(spf),
|
|
148
|
+
)
|
|
149
|
+
if kind in {"a", "mx", "ptr"}:
|
|
150
|
+
valid = (
|
|
151
|
+
re.fullmatch(
|
|
152
|
+
r"(?:a|mx|ptr)(?::[a-z0-9.-]+)?(?:/[0-9]{1,2})?(?://[0-9]{1,3})?", mechanism
|
|
153
|
+
)
|
|
154
|
+
is not None
|
|
155
|
+
)
|
|
156
|
+
elif kind == "ip4":
|
|
157
|
+
try:
|
|
158
|
+
ipaddress.IPv4Network(argument, strict=False)
|
|
159
|
+
valid = (
|
|
160
|
+
bool(separator) and "/" not in mechanism.partition(":")[2].partition("/")[0]
|
|
161
|
+
)
|
|
162
|
+
except ValueError:
|
|
163
|
+
valid = False
|
|
164
|
+
elif kind == "ip6":
|
|
165
|
+
try:
|
|
166
|
+
ipaddress.IPv6Network(argument, strict=False)
|
|
167
|
+
valid = bool(separator)
|
|
168
|
+
except ValueError:
|
|
169
|
+
valid = False
|
|
170
|
+
elif kind in {"include", "exists"}:
|
|
171
|
+
valid = bool(
|
|
172
|
+
separator
|
|
173
|
+
and argument
|
|
174
|
+
and "." in argument
|
|
175
|
+
and re.fullmatch(r"[a-z0-9.-]+", argument)
|
|
176
|
+
)
|
|
177
|
+
elif kind == "all":
|
|
178
|
+
valid = True
|
|
179
|
+
else:
|
|
180
|
+
valid = False
|
|
181
|
+
if not valid:
|
|
182
|
+
return Finding(
|
|
183
|
+
"spf",
|
|
184
|
+
"fail",
|
|
185
|
+
"error",
|
|
186
|
+
"SPF contains an unrecognized or malformed mechanism.",
|
|
187
|
+
tuple(spf),
|
|
188
|
+
)
|
|
189
|
+
if sum(m.split(":", 1)[0].split("/", 1)[0] == "all" for m in mechanisms) > 1:
|
|
190
|
+
return Finding(
|
|
191
|
+
"spf", "fail", "error", "SPF contains more than one 'all' mechanism.", tuple(spf)
|
|
192
|
+
)
|
|
193
|
+
return Finding(
|
|
194
|
+
"spf",
|
|
195
|
+
"pass",
|
|
196
|
+
"info",
|
|
197
|
+
"Exactly one SPF policy was found; this MVP checks presence and basic syntax, "
|
|
198
|
+
"not evaluation.",
|
|
199
|
+
tuple(spf),
|
|
200
|
+
)
|
|
201
|
+
|
|
202
|
+
def _check_dmarc(self, name: str) -> Finding:
|
|
203
|
+
records, issue = self._txt(f"_dmarc.{name}", "dmarc")
|
|
204
|
+
if issue:
|
|
205
|
+
return issue
|
|
206
|
+
policies = [r for r in records if r.lower().startswith("v=dmarc1")]
|
|
207
|
+
if len(policies) != 1:
|
|
208
|
+
return Finding(
|
|
209
|
+
"dmarc",
|
|
210
|
+
"fail",
|
|
211
|
+
"warning" if not policies else "error",
|
|
212
|
+
"No DMARC policy found." if not policies else "Multiple DMARC policies found.",
|
|
213
|
+
tuple(policies),
|
|
214
|
+
)
|
|
215
|
+
tags: dict[str, str] = {}
|
|
216
|
+
for token in policies[0].split(";"):
|
|
217
|
+
if not token.strip():
|
|
218
|
+
continue
|
|
219
|
+
if "=" not in token:
|
|
220
|
+
return Finding(
|
|
221
|
+
"dmarc", "fail", "error", "DMARC contains a tag without '='.", tuple(policies)
|
|
222
|
+
)
|
|
223
|
+
key, value = (part.strip() for part in token.split("=", 1))
|
|
224
|
+
key = key.lower()
|
|
225
|
+
if not re.fullmatch(r"[a-z][a-z0-9_]*", key) or key in tags:
|
|
226
|
+
return Finding(
|
|
227
|
+
"dmarc",
|
|
228
|
+
"fail",
|
|
229
|
+
"error",
|
|
230
|
+
"DMARC contains an invalid or duplicate tag.",
|
|
231
|
+
tuple(policies),
|
|
232
|
+
)
|
|
233
|
+
tags[key] = value
|
|
234
|
+
ordered_tags = [part.strip() for part in policies[0].split(";") if part.strip()]
|
|
235
|
+
if not ordered_tags[0].lower().startswith("v="):
|
|
236
|
+
return Finding(
|
|
237
|
+
"dmarc", "fail", "error", "DMARC version tag must appear first.", tuple(policies)
|
|
238
|
+
)
|
|
239
|
+
if tags.get("v", "").upper() != "DMARC1" or tags.get("p", "").lower() not in {
|
|
240
|
+
"none",
|
|
241
|
+
"quarantine",
|
|
242
|
+
"reject",
|
|
243
|
+
}:
|
|
244
|
+
return Finding(
|
|
245
|
+
"dmarc",
|
|
246
|
+
"fail",
|
|
247
|
+
"error",
|
|
248
|
+
"DMARC requires v=DMARC1 and p=none, quarantine, or reject.",
|
|
249
|
+
tuple(policies),
|
|
250
|
+
)
|
|
251
|
+
if "pct" in tags and (not tags["pct"].isdigit() or int(tags["pct"]) > 100):
|
|
252
|
+
return Finding(
|
|
253
|
+
"dmarc",
|
|
254
|
+
"fail",
|
|
255
|
+
"error",
|
|
256
|
+
"DMARC pct must be an integer from 0 to 100.",
|
|
257
|
+
tuple(policies),
|
|
258
|
+
)
|
|
259
|
+
if "rua" in tags and not all(
|
|
260
|
+
re.fullmatch(r"mailto:[^,!;\s]+(?:![0-9]+[kmg]?)?", uri.strip(), re.I)
|
|
261
|
+
for uri in tags["rua"].split(",")
|
|
262
|
+
):
|
|
263
|
+
return Finding(
|
|
264
|
+
"dmarc",
|
|
265
|
+
"fail",
|
|
266
|
+
"error",
|
|
267
|
+
"DMARC rua must contain valid mailto URIs.",
|
|
268
|
+
tuple(policies),
|
|
269
|
+
)
|
|
270
|
+
return Finding(
|
|
271
|
+
"dmarc",
|
|
272
|
+
"pass",
|
|
273
|
+
"info",
|
|
274
|
+
"One DMARC policy with valid version and policy tags was found.",
|
|
275
|
+
tuple(policies),
|
|
276
|
+
)
|
|
277
|
+
|
|
278
|
+
def _check_caa(self, name: str) -> Finding:
|
|
279
|
+
rows, error = self._query(name, "CAA")
|
|
280
|
+
if error and error != "no records":
|
|
281
|
+
return Finding("caa", "error", "warning", f"Could not query CAA records: {error}")
|
|
282
|
+
if not rows:
|
|
283
|
+
return Finding(
|
|
284
|
+
"caa",
|
|
285
|
+
"fail",
|
|
286
|
+
"warning",
|
|
287
|
+
"No CAA records found; any CA may be authorized by default.",
|
|
288
|
+
)
|
|
289
|
+
for row in rows:
|
|
290
|
+
parts = row.split(None, 2)
|
|
291
|
+
if (
|
|
292
|
+
len(parts) != 3
|
|
293
|
+
or not parts[0].isdigit()
|
|
294
|
+
or int(parts[0]) > 255
|
|
295
|
+
or parts[1].lower() not in {"issue", "issuewild", "iodef"}
|
|
296
|
+
):
|
|
297
|
+
return Finding(
|
|
298
|
+
"caa",
|
|
299
|
+
"fail",
|
|
300
|
+
"error",
|
|
301
|
+
"Malformed CAA record (expected flags tag value).",
|
|
302
|
+
tuple(rows),
|
|
303
|
+
)
|
|
304
|
+
return Finding(
|
|
305
|
+
"caa",
|
|
306
|
+
"pass",
|
|
307
|
+
"info",
|
|
308
|
+
"CAA records are present and have recognized tags and flags.",
|
|
309
|
+
tuple(rows),
|
|
310
|
+
)
|
|
311
|
+
|
|
312
|
+
def _check_mx(self, name: str) -> Finding:
|
|
313
|
+
rows, error = self._query(name, "MX")
|
|
314
|
+
if error and error != "no records":
|
|
315
|
+
return Finding("mx", "error", "warning", f"Could not query MX records: {error}")
|
|
316
|
+
if not rows:
|
|
317
|
+
return Finding(
|
|
318
|
+
"mx",
|
|
319
|
+
"pass",
|
|
320
|
+
"info",
|
|
321
|
+
"No MX records found; this domain does not advertise inbound mail.",
|
|
322
|
+
)
|
|
323
|
+
parsed: list[tuple[int, str]] = []
|
|
324
|
+
for row in rows:
|
|
325
|
+
parts = row.split()
|
|
326
|
+
if len(parts) != 2 or not parts[0].isdigit():
|
|
327
|
+
return Finding(
|
|
328
|
+
"mx",
|
|
329
|
+
"fail",
|
|
330
|
+
"error",
|
|
331
|
+
"Malformed MX record; expected preference and exchange.",
|
|
332
|
+
tuple(rows),
|
|
333
|
+
)
|
|
334
|
+
target = parts[1].rstrip(".").lower()
|
|
335
|
+
if target == "" and len(rows) == 1 and int(parts[0]) == 0:
|
|
336
|
+
return Finding(
|
|
337
|
+
"mx",
|
|
338
|
+
"pass",
|
|
339
|
+
"info",
|
|
340
|
+
"Null MX explicitly declares that this domain accepts no mail.",
|
|
341
|
+
tuple(rows),
|
|
342
|
+
)
|
|
343
|
+
if target == "" or int(parts[0]) > 65535:
|
|
344
|
+
return Finding(
|
|
345
|
+
"mx", "fail", "error", "MX preference or exchange is invalid.", tuple(rows)
|
|
346
|
+
)
|
|
347
|
+
try:
|
|
348
|
+
normalize_domain(target)
|
|
349
|
+
except ValueError:
|
|
350
|
+
return Finding(
|
|
351
|
+
"mx", "fail", "error", "MX exchange is not a valid DNS hostname.", tuple(rows)
|
|
352
|
+
)
|
|
353
|
+
parsed.append((int(parts[0]), target))
|
|
354
|
+
if len({target for _, target in parsed}) != len(parsed):
|
|
355
|
+
return Finding(
|
|
356
|
+
"mx", "fail", "error", "Duplicate MX exchange records were found.", tuple(rows)
|
|
357
|
+
)
|
|
358
|
+
return Finding(
|
|
359
|
+
"mx",
|
|
360
|
+
"pass",
|
|
361
|
+
"info",
|
|
362
|
+
"MX records have valid preference and exchange fields.",
|
|
363
|
+
tuple(rows),
|
|
364
|
+
)
|
|
365
|
+
|
|
366
|
+
def _check_ns(self, name: str) -> Finding:
|
|
367
|
+
rows, error = self._query(name, "NS")
|
|
368
|
+
if error and error != "no records":
|
|
369
|
+
return Finding("ns", "error", "warning", f"Could not query NS records: {error}")
|
|
370
|
+
targets = {row.rstrip(".").lower() for row in rows}
|
|
371
|
+
if not targets:
|
|
372
|
+
return Finding("ns", "fail", "error", "No authoritative NS records were returned.")
|
|
373
|
+
if len(targets) < 2:
|
|
374
|
+
return Finding(
|
|
375
|
+
"ns",
|
|
376
|
+
"fail",
|
|
377
|
+
"warning",
|
|
378
|
+
"Only one distinct NS target was found; consider provider and network diversity.",
|
|
379
|
+
tuple(rows),
|
|
380
|
+
)
|
|
381
|
+
return Finding(
|
|
382
|
+
"ns",
|
|
383
|
+
"pass",
|
|
384
|
+
"info",
|
|
385
|
+
"At least two distinct NS targets were found; provider independence is not verified.",
|
|
386
|
+
tuple(sorted(targets)),
|
|
387
|
+
)
|
|
388
|
+
|
|
389
|
+
def _check_dnssec_presence(self, name: str) -> Finding:
|
|
390
|
+
found: list[str] = []
|
|
391
|
+
errors: list[str] = []
|
|
392
|
+
for kind in ("DNSKEY", "DS"):
|
|
393
|
+
rows, error = self._query(name, kind)
|
|
394
|
+
if rows:
|
|
395
|
+
found.append(kind)
|
|
396
|
+
elif error and error != "no records":
|
|
397
|
+
errors.append(f"{kind}: {error}")
|
|
398
|
+
if errors:
|
|
399
|
+
return Finding(
|
|
400
|
+
"dnssec_record_presence",
|
|
401
|
+
"unknown",
|
|
402
|
+
"warning",
|
|
403
|
+
"Could not complete DNSSEC record-presence checks: " + "; ".join(errors),
|
|
404
|
+
tuple(found),
|
|
405
|
+
)
|
|
406
|
+
if len(found) == 2:
|
|
407
|
+
return Finding(
|
|
408
|
+
"dnssec_record_presence",
|
|
409
|
+
"pass",
|
|
410
|
+
"info",
|
|
411
|
+
"DNSKEY and DS records were observed. This is a presence check only; signatures "
|
|
412
|
+
"and chain of trust were not cryptographically validated.",
|
|
413
|
+
tuple(found),
|
|
414
|
+
)
|
|
415
|
+
return Finding(
|
|
416
|
+
"dnssec_record_presence",
|
|
417
|
+
"fail",
|
|
418
|
+
"warning",
|
|
419
|
+
"DNSKEY and/or DS records were not observed. This is not a cryptographic DNSSEC "
|
|
420
|
+
"validation result.",
|
|
421
|
+
tuple(found),
|
|
422
|
+
)
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"""Command-line interface for DNS Sentinel."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import json
|
|
7
|
+
import sys
|
|
8
|
+
|
|
9
|
+
from dns_sentinel import Auditor, __version__
|
|
10
|
+
from dns_sentinel.auditor import normalize_domain
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def main() -> int:
|
|
14
|
+
parser = argparse.ArgumentParser(description="Read-only DNS security configuration audit")
|
|
15
|
+
parser.add_argument("domain", help="Domain name, such as example.com")
|
|
16
|
+
parser.add_argument("--json", action="store_true", help="Emit machine-readable JSON")
|
|
17
|
+
parser.add_argument(
|
|
18
|
+
"--timeout", type=float, default=2.0, help="Per-query DNS timeout in seconds"
|
|
19
|
+
)
|
|
20
|
+
parser.add_argument(
|
|
21
|
+
"--lifetime", type=float, default=5.0, help="Maximum lifetime per DNS query in seconds"
|
|
22
|
+
)
|
|
23
|
+
parser.add_argument("--version", action="version", version=f"dns-sentinel {__version__}")
|
|
24
|
+
args = parser.parse_args()
|
|
25
|
+
try:
|
|
26
|
+
domain = normalize_domain(args.domain)
|
|
27
|
+
report = Auditor(timeout=args.timeout, lifetime=args.lifetime).audit(domain)
|
|
28
|
+
except ValueError as exc:
|
|
29
|
+
parser.error(str(exc))
|
|
30
|
+
except Exception as exc: # Last-resort boundary for an OS/resolver failure.
|
|
31
|
+
print(f"dns-sentinel: audit could not complete: {exc}", file=sys.stderr)
|
|
32
|
+
return 2
|
|
33
|
+
if args.json:
|
|
34
|
+
print(json.dumps(report.to_dict(), indent=2))
|
|
35
|
+
else:
|
|
36
|
+
print(f"DNS Sentinel audit: {report.domain}")
|
|
37
|
+
for finding in report.findings:
|
|
38
|
+
print(f"[{finding.status.upper():7}] {finding.check}: {finding.message}")
|
|
39
|
+
for item in finding.evidence:
|
|
40
|
+
print(f" {item}")
|
|
41
|
+
return 0 if report.passed else 1
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
if __name__ == "__main__":
|
|
45
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import dns.exception
|
|
4
|
+
import dns.resolver
|
|
5
|
+
import pytest
|
|
6
|
+
|
|
7
|
+
from dns_sentinel.auditor import Auditor, normalize_domain
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Answer(list[str]):
|
|
11
|
+
@property
|
|
12
|
+
def rrset(self) -> object:
|
|
13
|
+
return self if self else None
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class Resolver:
|
|
17
|
+
def __init__(self, data: dict[tuple[str, str], list[str] | Exception]):
|
|
18
|
+
self.data = data
|
|
19
|
+
|
|
20
|
+
def resolve(self, name: str, kind: str, **kwargs: object) -> Answer:
|
|
21
|
+
value = self.data.get((name, kind), [])
|
|
22
|
+
if isinstance(value, Exception):
|
|
23
|
+
raise value
|
|
24
|
+
return Answer(value)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def auditor(data: dict[tuple[str, str], list[str] | Exception]) -> Auditor:
|
|
28
|
+
return Auditor(resolver=Resolver(data))
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@pytest.mark.parametrize(
|
|
32
|
+
"value,expected", [("Example.COM.", "example.com"), ("bücher.de", "xn--bcher-kva.de")]
|
|
33
|
+
)
|
|
34
|
+
def test_domain_normalization(value: str, expected: str) -> None:
|
|
35
|
+
assert normalize_domain(value) == expected
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@pytest.mark.parametrize("value", ["", "https://example.com", "localhost", "-bad.example", "a..b"])
|
|
39
|
+
def test_domain_rejects_invalid_input(value: str) -> None:
|
|
40
|
+
with pytest.raises(ValueError):
|
|
41
|
+
normalize_domain(value)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def test_spf_requires_one_policy_and_rejects_duplicates() -> None:
|
|
45
|
+
a = auditor({("example.com", "TXT"): ['"v=spf1 -all"', '"hello"']})
|
|
46
|
+
assert a.audit("example.com").findings[0].status == "pass"
|
|
47
|
+
b = auditor({("example.com", "TXT"): ['"v=spf1 -all"', '"v=spf1 ~all"']})
|
|
48
|
+
result = b.audit("example.com").findings[0]
|
|
49
|
+
assert result.status == "fail" and result.severity == "error"
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def test_spf_rejects_malformed_mechanism() -> None:
|
|
53
|
+
a = auditor({("example.com", "TXT"): ['"v=spf1 ip4:not-an-ip -all"']})
|
|
54
|
+
assert a.audit("example.com").findings[0].status == "fail"
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
@pytest.mark.parametrize(
|
|
58
|
+
"record,expected",
|
|
59
|
+
[
|
|
60
|
+
("v=DMARC1; p=reject; pct=100", "pass"),
|
|
61
|
+
("v=DMARC1; p=invalid", "fail"),
|
|
62
|
+
("v=DMARC1; p=none; pct=101", "fail"),
|
|
63
|
+
("v=DMARC1; p=none; p=reject", "fail"),
|
|
64
|
+
],
|
|
65
|
+
)
|
|
66
|
+
def test_dmarc_policy_validation(record: str, expected: str) -> None:
|
|
67
|
+
result = (
|
|
68
|
+
auditor({("_dmarc.example.com", "TXT"): [f'"{record}"']}).audit("example.com").findings[1]
|
|
69
|
+
)
|
|
70
|
+
assert result.status == expected
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def test_dmarc_requires_version_first_and_accepts_rua_size() -> None:
|
|
74
|
+
wrong_order = (
|
|
75
|
+
auditor({("_dmarc.example.com", "TXT"): ['"p=reject; v=DMARC1"']})
|
|
76
|
+
.audit("example.com")
|
|
77
|
+
.findings[1]
|
|
78
|
+
)
|
|
79
|
+
assert wrong_order.status == "fail"
|
|
80
|
+
valid_uri = (
|
|
81
|
+
auditor(
|
|
82
|
+
{
|
|
83
|
+
("_dmarc.example.com", "TXT"): [
|
|
84
|
+
'"v=DMARC1; p=reject; rua=mailto:reports@example.com!10m"'
|
|
85
|
+
]
|
|
86
|
+
}
|
|
87
|
+
)
|
|
88
|
+
.audit("example.com")
|
|
89
|
+
.findings[1]
|
|
90
|
+
)
|
|
91
|
+
assert valid_uri.status == "pass"
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def test_caa_mx_ns_checks() -> None:
|
|
95
|
+
data = {
|
|
96
|
+
("example.com", "CAA"): ['0 issue "letsencrypt.org"'],
|
|
97
|
+
("example.com", "MX"): ["10 mail.example.com."],
|
|
98
|
+
("example.com", "NS"): ["ns1.example.net.", "ns2.example.net."],
|
|
99
|
+
}
|
|
100
|
+
findings = auditor(data).audit("example.com").findings
|
|
101
|
+
assert [findings[i].status for i in (2, 3, 4)] == ["pass", "pass", "pass"]
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def test_null_mx_and_malformed_caa() -> None:
|
|
105
|
+
data = {("example.com", "MX"): ["0 ."], ("example.com", "CAA"): ["999 nonsense value"]}
|
|
106
|
+
findings = auditor(data).audit("example.com").findings
|
|
107
|
+
assert findings[2].status == "fail"
|
|
108
|
+
assert findings[3].status == "pass"
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def test_dnssec_is_explicitly_presence_only() -> None:
|
|
112
|
+
data = {("example.com", "DNSKEY"): ["256 3 13 abc"], ("example.com", "DS"): ["1 1 1 abc"]}
|
|
113
|
+
result = auditor(data).audit("example.com").findings[-1]
|
|
114
|
+
assert result.status == "pass"
|
|
115
|
+
assert "not cryptographically validated" in result.message
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def test_dns_errors_do_not_abort_other_checks() -> None:
|
|
119
|
+
data = {
|
|
120
|
+
("example.com", "TXT"): dns.resolver.NXDOMAIN(),
|
|
121
|
+
("example.com", "CAA"): dns.exception.Timeout(),
|
|
122
|
+
("example.com", "NS"): ["ns1.example.net.", "ns2.example.net."],
|
|
123
|
+
}
|
|
124
|
+
findings = auditor(data).audit("example.com").findings
|
|
125
|
+
assert len(findings) == 6
|
|
126
|
+
assert findings[2].severity == "warning"
|
|
127
|
+
assert findings[4].status == "pass"
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
@pytest.mark.parametrize(
|
|
131
|
+
"failure", [dns.resolver.LifetimeTimeout(timeout=1, errors=[]), dns.resolver.NoNameservers()]
|
|
132
|
+
)
|
|
133
|
+
def test_resolver_failures_are_reported_as_warnings(failure: Exception) -> None:
|
|
134
|
+
result = auditor({("example.com", "CAA"): failure}).audit("example.com").findings[2]
|
|
135
|
+
assert result.severity == "warning"
|
|
136
|
+
assert "Could not query" in result.message
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def test_mx_rejects_invalid_preference() -> None:
|
|
140
|
+
result = (
|
|
141
|
+
auditor({("example.com", "MX"): ["70000 mail.example.com."]})
|
|
142
|
+
.audit("example.com")
|
|
143
|
+
.findings[3]
|
|
144
|
+
)
|
|
145
|
+
assert result.status == "fail"
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def test_ns_duplicate_target_does_not_fake_redundancy() -> None:
|
|
149
|
+
result = (
|
|
150
|
+
auditor({("example.com", "NS"): ["ns1.example.net.", "NS1.example.net."]})
|
|
151
|
+
.audit("example.com")
|
|
152
|
+
.findings[4]
|
|
153
|
+
)
|
|
154
|
+
assert result.status == "fail"
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def test_report_json_shape() -> None:
|
|
158
|
+
report = auditor({}).audit("example.com")
|
|
159
|
+
assert report.to_dict()["domain"] == "example.com"
|
|
160
|
+
assert len(report.to_dict()["findings"]) == 6
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
|
|
5
|
+
import pytest
|
|
6
|
+
|
|
7
|
+
from dns_sentinel import cli
|
|
8
|
+
from dns_sentinel.auditor import Finding, Report
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def test_cli_json_output_and_exit_code(
|
|
12
|
+
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
|
|
13
|
+
) -> None:
|
|
14
|
+
report = Report("example.com", (Finding("spf", "pass", "info", "ok"),))
|
|
15
|
+
monkeypatch.setattr(cli.sys, "argv", ["dns-sentinel", "example.com", "--json"])
|
|
16
|
+
monkeypatch.setattr(
|
|
17
|
+
cli, "Auditor", lambda **kwargs: type("Fake", (), {"audit": lambda self, name: report})()
|
|
18
|
+
)
|
|
19
|
+
assert cli.main() == 0
|
|
20
|
+
assert json.loads(capsys.readouterr().out)["domain"] == "example.com"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def test_cli_nonzero_for_error_findings(
|
|
24
|
+
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
|
|
25
|
+
) -> None:
|
|
26
|
+
report = Report("example.com", (Finding("spf", "fail", "error", "bad"),))
|
|
27
|
+
monkeypatch.setattr(cli.sys, "argv", ["dns-sentinel", "example.com"])
|
|
28
|
+
monkeypatch.setattr(
|
|
29
|
+
cli, "Auditor", lambda **kwargs: type("Fake", (), {"audit": lambda self, name: report})()
|
|
30
|
+
)
|
|
31
|
+
assert cli.main() == 1
|
|
32
|
+
assert "spf" in capsys.readouterr().out
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
|
|
3
|
+
from dns_sentinel import Auditor
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@pytest.mark.integration
|
|
7
|
+
def test_public_dns_end_to_end() -> None:
|
|
8
|
+
report = Auditor(timeout=3, lifetime=8).audit("example.com")
|
|
9
|
+
assert report.domain == "example.com"
|
|
10
|
+
assert {finding.check for finding in report.findings} == {
|
|
11
|
+
"spf",
|
|
12
|
+
"dmarc",
|
|
13
|
+
"caa",
|
|
14
|
+
"mx",
|
|
15
|
+
"ns",
|
|
16
|
+
"dnssec_record_presence",
|
|
17
|
+
}
|
|
18
|
+
assert all(
|
|
19
|
+
finding.status in {"pass", "fail", "error", "unknown"} for finding in report.findings
|
|
20
|
+
)
|