惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

C
CXSECURITY Database RSS Feed - CXSecurity.com
Help Net Security
Help Net Security
P
Privacy International News Feed
S
Securelist
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Tor Project blog
AWS News Blog
AWS News Blog
K
Kaspersky official blog
A
Arctic Wolf
Latest news
Latest news
T
Threat Research - Cisco Blogs
L
LINUX DO - 最新话题
P
Privacy & Cybersecurity Law Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
Google DeepMind News
Google DeepMind News
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
月光博客
月光博客
N
News and Events Feed by Topic
Jina AI
Jina AI
博客园 - 司徒正美
WordPress大学
WordPress大学
罗磊的独立博客
雷峰网
雷峰网
AI
AI
Hugging Face - Blog
Hugging Face - Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
S
Security @ Cisco Blogs
博客园 - 三生石上(FineUI控件)
H
Heimdal Security Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
酷 壳 – CoolShell
酷 壳 – CoolShell
C
Cisco Blogs
博客园 - 【当耐特】
The Hacker News
The Hacker News
有赞技术团队
有赞技术团队
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Schneier on Security
Schneier on Security
博客园 - Franky
S
SegmentFault 最新的问题
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Cloudbric
Cloudbric
爱范儿
爱范儿
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
S
Secure Thoughts
Last Week in AI
Last Week in AI
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Know Your Adversary
Know Your Adversary
Google DeepMind News
Google DeepMind News

Blogs on CoreDNS: DNS and Service Discovery

CoreDNS-1.14.2 Release CoreDNS-1.14.1 Release CoreDNS-1.14.0 Release CoreDNS-1.13.2 Release CoreDNS-1.13.1 Release CoreDNS-1.13.0 Release CoreDNS-1.12.4 Release CoreDNS-1.12.3 Release CoreDNS-1.12.2 Release CoreDNS-1.12.1 Release CoreDNS-1.12.0 Release CoreDNS-1.11.4 Release CoreDNS-1.11.3 Release CoreDNS-1.11.2 Release CoreDNS-1.11.1 Release CoreDNS-1.11.0 Release CoreDNS-1.10.1 Release CoreDNS-1.10.0 Release CoreDNS-1.9.4 Release CoreDNS-1.9.3 Release CoreDNS-1.9.2 Release CoreDNS-1.9.1 Release CoreDNS and Apache APISIX open new doors for Service Discovery? Trail Of Bits Security Review CoreDNS-1.9.0 Release CoreDNS-1.8.7 Release CoreDNS-1.8.6 Release CoreDNS-1.8.5 Release CoreDNS-1.8.4 Release CoreDNS-1.8.3 Release CoreDNS-1.8.2 Release CoreDNS-1.8.1 Release CoreDNS-1.8.0 Release CoreDNS-1.7.1 Release CoreDNS-1.7.0 Release CoreDNS-1.6.8 Release CoreDNS-1.6.9 Release CoreDNS-1.6.7 Release CoreDNS-1.6.6 Release CoreDNS-1.6.5 Release CoreDNS-1.6.4 Release CoreDNS-1.6.3 Release CoreDNS-1.6.2 Release CoreDNS-1.6.1 Release CoreDNS-1.6.0 Release CoreDNS-1.5.2 Release CoreDNS-1.5.1 Release CoreDNS-1.5.0 Release CoreDNS-1.4.0 Release CoreDNS-1.3.1 Release CoreDNS-1.3.0 Release Cluster DNS: CoreDNS vs Kube-DNS Scaling CoreDNS in Kubernetes Clusters CoreDNS-1.2.6 Release CoreDNS-1.2.5 Release CoreDNS-1.2.4 Release CoreDNS-1.2.3 Release CoreDNS-1.2.2 Release CoreDNS-1.2.1 Release CoreDNS-1.2.0 Release CoreDNS-1.1.4 Release CoreDNS-1.1.3 Release Migration from kube-dns to CoreDNS CoreDNS-1.1.2 Release CoreDNS-1.1.1 Release Cure53 Security Assessment CoreDNS-1.1.0 Release CoreDNS-1.0.6 Release Deploying Kubernetes with CoreDNS using kubeadm CoreDNS-1.0.5 Release CoreDNS-1.0.4 Release CoreDNS-1.0.3 Release CoreDNS-1.0.2 Release CoreDNS-1.0.1 Release CoreDNS-1.0.0 Release CoreDNS-0.9.10 Release Setting up CoreDNS (on AWS) CoreDNS-0.9.9 Release Semantic Versioning CoreDNS-011 Release A first look at CoreDNS CoreDNS Performance Testing Logging with dnstap Intro to CoreDNS webinar by John Belamaric CoreDNS-010 Release Compile Time Enabling or Disabling Plugins When Should Plugins be External? Add External Plugins Corefile Explained CoreDNS-009 Release CoreDNS-008 Release How Queries Are Processed in CoreDNS Custom DNS Entries For Kubernetes CoreDNS-007 Release CoreDNS for Minikube Why CNCF for CoreDNS? CoreDNS for Kubernetes Service Discovery, Take 2 How to Add Plugins to CoreDNS History of CoreDNS in four posts. CoreDNS-006 Release
Writing Plugins for CoreDNS
miek · 2016-12-19 · via Blogs on CoreDNS: DNS and Service Discovery

A plugin adds functionality to CoreDNS, i.e. caching, metrics and basic zone file serving are all plugins.

If you want to write a new plugin and want it to be included by default, i.e. merged in the code base please open an issue first to discuss initial design and other things that may come up. Starting with a README file to explain how things work from a user perspective is usually a good idea.

See the example plugin for, uh, an example for how to structure, write and test a plugin. There are plenty of comments in the code to help you along.

How to Register a CoreDNS Plugin?

When writing your plugin code you will need to register it with CoreDNS. This can be done by calling the following function:

func init() { plugin.Register("foo", setup) }

Every plugin must have a name, foo, in this case. When foo is encountered in the configuration the setup function will be called in this package.

The Setup Function

The setup function (it may be called different, but pretty much every plugin just calls it setup) parses the configuration and populates internal data structures.

The setup function a caddy.Controller and returns an error: (We use plugin.Error to prefix returned error with plugin/foo: to improve error reporting).

func setup(c *caddy.Controller) error {
  if err != nil {
    return plugin.Error("foo", err)
  }

  // various other code

  return nil
}

If we see a line in the Corefile such as:

foo gizmo

We can get the value of the first argument (“gizmo”) like so:

for c.Next() {              // Skip the plugin name, "foo" in this case.
    if !c.NextArg() {       // Expect at least one value.
        return c.ArgErr()   // Otherwise it's an error.
    }
    value := c.Val()        // Use the value.
}

You parse the tokens present for your plugin by iterating over c.Next() which is true as long as there are more tokens to parse. Since a plugin may appear multiple times, you must iterate over c.Next() to get all the appearances of your plugin and consume the tokens.

Adding to CoreDNS

To plug your plugin into CoreDNS, put in plugin.cfg and run go generate.

If you’re working with an external, non core, plugin it will be easiest to make a symlink from the plugin directory to your plugin. I.e.

cd plugin
ln -s ../../example .
cd ..
vi plugin.cfg # add example:example
go generate
go build

How A Plugin Works in CoreDNS

Check out the godoc for the plugin package. The most important type is plugin.Handler.

A Handler is a function that handles a DNS request. CoreDNS will do all the bookkeeping of setting up an DNS server for you, but you need to implement these two types.

Writing a Handler

plugin.Handler is an interface similar to http.Handler except that it deals with DNS and the ServeDNS method returns (int, error). The int is status code, and the error is logged (if not nil) See plugin.md for more details about these return values.

Handlers are usually a struct with at least one field, the next Handler in the chain:

type MyHandler struct {
  Next plugin.Handler
}

To implement the plugin.Handler interface, we write a method called ServeDNS. This method is the actual handler function, and, unless it fully handles the request by itself, it should call the next handler in the chain:

func (h MyHandler) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
  return h.Next.ServeDNS(ctx, w, r)
}

The interface also needs a method func Name() string.,

func (h MyHandler) Name() string { return "foo" }

That’s all there is to it (apart from writing all code that actually does something with the DNS request of course).

Further Reading

Simple examples of plugin that can be found in CoreDNS are:

  • root; does not register itself as a plugin. It simply performs some setup.
  • chaos; a DNS plugin that responds to CH txt version.bind requests.
  • example; an example plugin that prints “example” when responding to a query.

Don’t forget: the best documentation is the godoc and the code itself!