Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
C
Coredns
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Railgun
Coredns
Commits
81484083
Commit
81484083
authored
Sep 25, 2018
by
Can Yucel
Committed by
corbot[bot]
Sep 25, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
plugins/route53: add AWS credentials file support (#2118)
Automatically submitted.
parent
a0396e26
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
75 additions
and
5 deletions
+75
-5
plugin/route53/README.md
plugin/route53/README.md
+16
-2
plugin/route53/setup.go
plugin/route53/setup.go
+27
-3
plugin/route53/setup_test.go
plugin/route53/setup_test.go
+32
-0
No files found.
plugin/route53/README.md
View file @
81484083
...
...
@@ -16,6 +16,7 @@ The route53 plugin can be used when coredns is deployed on AWS or elsewhere.
route53 [ZONE:HOSTED_ZONE_ID...] {
[aws_access_key AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY]
upstream [ADDRESS...]
credentials PROFILE [FILENAME]
fallthrough [ZONES...]
}
~~~
...
...
@@ -30,6 +31,9 @@ route53 [ZONE:HOSTED_ZONE_ID...] {
to external hosts (eg. used to resolve CNAMEs). If no
**ADDRESS**
is given, CoreDNS will resolve
against itself.
**ADDRESS**
can be an IP, an IP:port or a path to a file structured like
resolv.conf (
**NB**
: Currently a bug (#2099) is preventing the use of self-resolver).
*
`credentials`
used for reading the credential file and setting the profile name for a given zone.
*
**PROFILE**
AWS account profile name. Defaults to
`default`
.
*
**FILENAME**
AWS credentials filename. Defaults to
`~/.aws/credentials`
are used.
*
`fallthrough`
If zone matches and no record can be generated, pass request to the next plugin.
If
**[ZONES...]**
is omitted, then fallthrough happens for all zones for which the plugin
...
...
@@ -39,7 +43,7 @@ route53 [ZONE:HOSTED_ZONE_ID...] {
## Examples
Enable route53 with implicit
aws
credentials and an upstream:
Enable route53 with implicit
AWS
credentials and an upstream:
~~~
txt
. {
...
...
@@ -48,7 +52,7 @@ Enable route53 with implicit aws credentials and an upstream:
}
~~~
Enable route53 with explicit
aws
credentials:
Enable route53 with explicit
AWS
credentials:
~~~
txt
. {
...
...
@@ -67,3 +71,13 @@ Enable route53 with fallthrough:
}
}
~~~
Enable route53 with AWS credentials file:
~~~
txt
. {
route53 example.org.:Z1Z2Z3Z4DZ5Z6Z7 {
credentials_file some-user
}
}
~~~
plugin/route53/setup.go
View file @
81484083
...
...
@@ -36,7 +36,15 @@ func init() {
func
setup
(
c
*
caddy
.
Controller
,
f
func
(
*
credentials
.
Credentials
)
route53iface
.
Route53API
)
error
{
keys
:=
map
[
string
]
string
{}
credential
:=
credentials
.
NewEnvCredentials
()
// Route53 plugin attempts to find AWS credentials by using ChainCredentials.
// And the order of that provider chain is as follows:
// Static AWS keys -> Environment Variables -> Credentials file -> IAM role
// With that said, even though a user doesn't define any credentials in
// Corefile, we should still attempt to read the default credentials file,
// ~/.aws/credentials with the default profile.
sharedProvider
:=
&
credentials
.
SharedCredentialsProvider
{}
var
providers
[]
credentials
.
Provider
var
fall
fall
.
F
up
,
_
:=
upstream
.
New
(
nil
)
...
...
@@ -65,7 +73,12 @@ func setup(c *caddy.Controller, f func(*credentials.Credentials) route53iface.Ro
if
len
(
v
)
<
2
{
return
c
.
Errf
(
"invalid access key '%v'"
,
v
)
}
credential
=
credentials
.
NewStaticCredentials
(
v
[
0
],
v
[
1
],
""
)
providers
=
append
(
providers
,
&
credentials
.
StaticProvider
{
Value
:
credentials
.
Value
{
AccessKeyID
:
v
[
0
],
SecretAccessKey
:
v
[
1
],
},
})
case
"upstream"
:
args
:=
c
.
RemainingArgs
()
// TODO(dilyevsky): There is a bug that causes coredns to crash
...
...
@@ -78,6 +91,15 @@ func setup(c *caddy.Controller, f func(*credentials.Credentials) route53iface.Ro
if
err
!=
nil
{
return
c
.
Errf
(
"invalid upstream: %v"
,
err
)
}
case
"credentials"
:
if
c
.
NextArg
()
{
sharedProvider
.
Profile
=
c
.
Val
()
}
else
{
return
c
.
ArgErr
()
}
if
c
.
NextArg
()
{
sharedProvider
.
Filename
=
c
.
Val
()
}
case
"fallthrough"
:
fall
.
SetZonesFromArgs
(
c
.
RemainingArgs
())
default
:
...
...
@@ -85,7 +107,9 @@ func setup(c *caddy.Controller, f func(*credentials.Credentials) route53iface.Ro
}
}
}
client
:=
f
(
credential
)
providers
=
append
(
providers
,
&
credentials
.
EnvProvider
{},
sharedProvider
)
client
:=
f
(
credentials
.
NewChainCredentials
(
providers
))
ctx
:=
context
.
Background
()
h
,
err
:=
New
(
ctx
,
client
,
keys
,
&
up
)
if
err
!=
nil
{
...
...
plugin/route53/setup_test.go
View file @
81484083
...
...
@@ -59,4 +59,36 @@ func TestSetupRoute53(t *testing.T) {
if
err
:=
setup
(
c
,
f
);
err
!=
nil
{
t
.
Fatalf
(
"Unexpected errors: %v"
,
err
)
}
c
=
caddy
.
NewTestController
(
"dns"
,
`route53 example.org:12345678 {
credentials
upstream 1.2.3.4
}`
)
if
err
:=
setup
(
c
,
f
);
err
==
nil
{
t
.
Fatalf
(
"Expected errors, but got: %v"
,
err
)
}
c
=
caddy
.
NewTestController
(
"dns"
,
`route53 example.org:12345678 {
credentials default
upstream 1.2.3.4
}`
)
if
err
:=
setup
(
c
,
f
);
err
!=
nil
{
t
.
Fatalf
(
"Unexpected errors: %v"
,
err
)
}
c
=
caddy
.
NewTestController
(
"dns"
,
`route53 example.org:12345678 {
credentials default credentials
upstream 1.2.3.4
}`
)
if
err
:=
setup
(
c
,
f
);
err
!=
nil
{
t
.
Fatalf
(
"Unexpected errors: %v"
,
err
)
}
c
=
caddy
.
NewTestController
(
"dns"
,
`route53 example.org:12345678 {
credentials default credentials extra-arg
upstream 1.2.3.4
}`
)
if
err
:=
setup
(
c
,
f
);
err
==
nil
{
t
.
Fatalf
(
"Expected errors, but got: %v"
,
err
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment