Skip to content

Commit 56acc25

Browse files
committed
Initial Fleet server
0 parents  commit 56acc25

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+6803
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
bin/
2+
*.rpm
3+
build/

LICENSE.txt

+223
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
ELASTIC LICENSE AGREEMENT
2+
3+
PLEASE READ CAREFULLY THIS ELASTIC LICENSE AGREEMENT (THIS "AGREEMENT"), WHICH
4+
CONSTITUTES A LEGALLY BINDING AGREEMENT AND GOVERNS ALL OF YOUR USE OF ALL OF
5+
THE ELASTIC SOFTWARE WITH WHICH THIS AGREEMENT IS INCLUDED ("ELASTIC SOFTWARE")
6+
THAT IS PROVIDED IN OBJECT CODE FORMAT, AND, IN ACCORDANCE WITH SECTION 2 BELOW,
7+
CERTAIN OF THE ELASTIC SOFTWARE THAT IS PROVIDED IN SOURCE CODE FORMAT. BY
8+
INSTALLING OR USING ANY OF THE ELASTIC SOFTWARE GOVERNED BY THIS AGREEMENT, YOU
9+
ARE ASSENTING TO THE TERMS AND CONDITIONS OF THIS AGREEMENT. IF YOU DO NOT AGREE
10+
WITH SUCH TERMS AND CONDITIONS, YOU MAY NOT INSTALL OR USE THE ELASTIC SOFTWARE
11+
GOVERNED BY THIS AGREEMENT. IF YOU ARE INSTALLING OR USING THE SOFTWARE ON
12+
BEHALF OF A LEGAL ENTITY, YOU REPRESENT AND WARRANT THAT YOU HAVE THE ACTUAL
13+
AUTHORITY TO AGREE TO THE TERMS AND CONDITIONS OF THIS AGREEMENT ON BEHALF OF
14+
SUCH ENTITY.
15+
16+
Posted Date: April 20, 2018
17+
18+
This Agreement is entered into by and between Elasticsearch BV ("Elastic") and
19+
You, or the legal entity on behalf of whom You are acting (as applicable,
20+
"You").
21+
22+
1. OBJECT CODE END USER LICENSES, RESTRICTIONS AND THIRD PARTY OPEN SOURCE
23+
SOFTWARE
24+
25+
1.1 Object Code End User License. Subject to the terms and conditions of
26+
Section 1.2 of this Agreement, Elastic hereby grants to You, AT NO CHARGE and
27+
for so long as you are not in breach of any provision of this Agreement, a
28+
License to the Basic Features and Functions of the Elastic Software.
29+
30+
1.2 Reservation of Rights; Restrictions. As between Elastic and You, Elastic
31+
and its licensors own all right, title and interest in and to the Elastic
32+
Software, and except as expressly set forth in Sections 1.1, and 2.1 of this
33+
Agreement, no other license to the Elastic Software is granted to You under
34+
this Agreement, by implication, estoppel or otherwise. You agree not to: (i)
35+
reverse engineer or decompile, decrypt, disassemble or otherwise reduce any
36+
Elastic Software provided to You in Object Code, or any portion thereof, to
37+
Source Code, except and only to the extent any such restriction is prohibited
38+
by applicable law, (ii) except as expressly permitted in this Agreement,
39+
prepare derivative works from, modify, copy or use the Elastic Software Object
40+
Code or the Commercial Software Source Code in any manner; (iii) except as
41+
expressly permitted in Section 1.1 above, transfer, sell, rent, lease,
42+
distribute, sublicense, loan or otherwise transfer, Elastic Software Object
43+
Code, in whole or in part, to any third party; (iv) use Elastic Software
44+
Object Code for providing time-sharing services, any software-as-a-service,
45+
service bureau services or as part of an application services provider or
46+
other service offering (collectively, "SaaS Offering") where obtaining access
47+
to the Elastic Software or the features and functions of the Elastic Software
48+
is a primary reason or substantial motivation for users of the SaaS Offering
49+
to access and/or use the SaaS Offering ("Prohibited SaaS Offering"); (v)
50+
circumvent the limitations on use of Elastic Software provided to You in
51+
Object Code format that are imposed or preserved by any License Key, or (vi)
52+
alter or remove any Marks and Notices in the Elastic Software. If You have any
53+
question as to whether a specific SaaS Offering constitutes a Prohibited SaaS
54+
Offering, or are interested in obtaining Elastic's permission to engage in
55+
commercial or non-commercial distribution of the Elastic Software, please
56+
contact elastic_license@elastic.co.
57+
58+
1.3 Third Party Open Source Software. The Commercial Software may contain or
59+
be provided with third party open source libraries, components, utilities and
60+
other open source software (collectively, "Open Source Software"), which Open
61+
Source Software may have applicable license terms as identified on a website
62+
designated by Elastic. Notwithstanding anything to the contrary herein, use of
63+
the Open Source Software shall be subject to the license terms and conditions
64+
applicable to such Open Source Software, to the extent required by the
65+
applicable licensor (which terms shall not restrict the license rights granted
66+
to You hereunder, but may contain additional rights). To the extent any
67+
condition of this Agreement conflicts with any license to the Open Source
68+
Software, the Open Source Software license will govern with respect to such
69+
Open Source Software only. Elastic may also separately provide you with
70+
certain open source software that is licensed by Elastic. Your use of such
71+
Elastic open source software will not be governed by this Agreement, but by
72+
the applicable open source license terms.
73+
74+
2. COMMERCIAL SOFTWARE SOURCE CODE
75+
76+
2.1 Limited License. Subject to the terms and conditions of Section 2.2 of
77+
this Agreement, Elastic hereby grants to You, AT NO CHARGE and for so long as
78+
you are not in breach of any provision of this Agreement, a limited,
79+
non-exclusive, non-transferable, fully paid up royalty free right and license
80+
to the Commercial Software in Source Code format, without the right to grant
81+
or authorize sublicenses, to prepare Derivative Works of the Commercial
82+
Software, provided You (i) do not hack the licensing mechanism, or otherwise
83+
circumvent the intended limitations on the use of Elastic Software to enable
84+
features other than Basic Features and Functions or those features You are
85+
entitled to as part of a Subscription, and (ii) use the resulting object code
86+
only for reasonable testing purposes.
87+
88+
2.2 Restrictions. Nothing in Section 2.1 grants You the right to (i) use the
89+
Commercial Software Source Code other than in accordance with Section 2.1
90+
above, (ii) use a Derivative Work of the Commercial Software outside of a
91+
Non-production Environment, in any production capacity, on a temporary or
92+
permanent basis, or (iii) transfer, sell, rent, lease, distribute, sublicense,
93+
loan or otherwise make available the Commercial Software Source Code, in whole
94+
or in part, to any third party. Notwithstanding the foregoing, You may
95+
maintain a copy of the repository in which the Source Code of the Commercial
96+
Software resides and that copy may be publicly accessible, provided that you
97+
include this Agreement with Your copy of the repository.
98+
99+
3. TERMINATION
100+
101+
3.1 Termination. This Agreement will automatically terminate, whether or not
102+
You receive notice of such Termination from Elastic, if You breach any of its
103+
provisions.
104+
105+
3.2 Post Termination. Upon any termination of this Agreement, for any reason,
106+
You shall promptly cease the use of the Elastic Software in Object Code format
107+
and cease use of the Commercial Software in Source Code format. For the
108+
avoidance of doubt, termination of this Agreement will not affect Your right
109+
to use Elastic Software, in either Object Code or Source Code formats, made
110+
available under the Apache License Version 2.0.
111+
112+
3.3 Survival. Sections 1.2, 2.2. 3.3, 4 and 5 shall survive any termination or
113+
expiration of this Agreement.
114+
115+
4. DISCLAIMER OF WARRANTIES AND LIMITATION OF LIABILITY
116+
117+
4.1 Disclaimer of Warranties. TO THE MAXIMUM EXTENT PERMITTED UNDER APPLICABLE
118+
LAW, THE ELASTIC SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
119+
AND ELASTIC AND ITS LICENSORS MAKE NO WARRANTIES WHETHER EXPRESSED, IMPLIED OR
120+
STATUTORY REGARDING OR RELATING TO THE ELASTIC SOFTWARE. TO THE MAXIMUM EXTENT
121+
PERMITTED UNDER APPLICABLE LAW, ELASTIC AND ITS LICENSORS SPECIFICALLY
122+
DISCLAIM ALL IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
123+
PURPOSE AND NON-INFRINGEMENT WITH RESPECT TO THE ELASTIC SOFTWARE, AND WITH
124+
RESPECT TO THE USE OF THE FOREGOING. FURTHER, ELASTIC DOES NOT WARRANT RESULTS
125+
OF USE OR THAT THE ELASTIC SOFTWARE WILL BE ERROR FREE OR THAT THE USE OF THE
126+
ELASTIC SOFTWARE WILL BE UNINTERRUPTED.
127+
128+
4.2 Limitation of Liability. IN NO EVENT SHALL ELASTIC OR ITS LICENSORS BE
129+
LIABLE TO YOU OR ANY THIRD PARTY FOR ANY DIRECT OR INDIRECT DAMAGES,
130+
INCLUDING, WITHOUT LIMITATION, FOR ANY LOSS OF PROFITS, LOSS OF USE, BUSINESS
131+
INTERRUPTION, LOSS OF DATA, COST OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY
132+
SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, IN CONNECTION WITH
133+
OR ARISING OUT OF THE USE OR INABILITY TO USE THE ELASTIC SOFTWARE, OR THE
134+
PERFORMANCE OF OR FAILURE TO PERFORM THIS AGREEMENT, WHETHER ALLEGED AS A
135+
BREACH OF CONTRACT OR TORTIOUS CONDUCT, INCLUDING NEGLIGENCE, EVEN IF ELASTIC
136+
HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
137+
138+
5. MISCELLANEOUS
139+
140+
This Agreement completely and exclusively states the entire agreement of the
141+
parties regarding the subject matter herein, and it supersedes, and its terms
142+
govern, all prior proposals, agreements, or other communications between the
143+
parties, oral or written, regarding such subject matter. This Agreement may be
144+
modified by Elastic from time to time, and any such modifications will be
145+
effective upon the "Posted Date" set forth at the top of the modified
146+
Agreement. If any provision hereof is held unenforceable, this Agreement will
147+
continue without said provision and be interpreted to reflect the original
148+
intent of the parties. This Agreement and any non-contractual obligation
149+
arising out of or in connection with it, is governed exclusively by Dutch law.
150+
This Agreement shall not be governed by the 1980 UN Convention on Contracts
151+
for the International Sale of Goods. All disputes arising out of or in
152+
connection with this Agreement, including its existence and validity, shall be
153+
resolved by the courts with jurisdiction in Amsterdam, The Netherlands, except
154+
where mandatory law provides for the courts at another location in The
155+
Netherlands to have jurisdiction. The parties hereby irrevocably waive any and
156+
all claims and defenses either might otherwise have in any such action or
157+
proceeding in any of such courts based upon any alleged lack of personal
158+
jurisdiction, improper venue, forum non conveniens or any similar claim or
159+
defense. A breach or threatened breach, by You of Section 2 may cause
160+
irreparable harm for which damages at law may not provide adequate relief, and
161+
therefore Elastic shall be entitled to seek injunctive relief without being
162+
required to post a bond. You may not assign this Agreement (including by
163+
operation of law in connection with a merger or acquisition), in whole or in
164+
part to any third party without the prior written consent of Elastic, which
165+
may be withheld or granted by Elastic in its sole and absolute discretion.
166+
Any assignment in violation of the preceding sentence is void. Notices to
167+
Elastic may also be sent to legal@elastic.co.
168+
169+
6. DEFINITIONS
170+
171+
The following terms have the meanings ascribed:
172+
173+
6.1 "Affiliate" means, with respect to a party, any entity that controls, is
174+
controlled by, or which is under common control with, such party, where
175+
"control" means ownership of at least fifty percent (50%) of the outstanding
176+
voting shares of the entity, or the contractual right to establish policy for,
177+
and manage the operations of, the entity.
178+
179+
6.2 "Basic Features and Functions" means those features and functions of the
180+
Elastic Software that are eligible for use under a Basic license, as set forth
181+
at https://www.elastic.co/subscriptions, as may be modified by Elastic from
182+
time to time.
183+
184+
6.3 "Commercial Software" means the Elastic Software Source Code in any file
185+
containing a header stating the contents are subject to the Elastic License or
186+
which is contained in the repository folder labeled "x-pack", unless a LICENSE
187+
file present in the directory subtree declares a different license.
188+
189+
6.4 "Derivative Work of the Commercial Software" means, for purposes of this
190+
Agreement, any modification(s) or enhancement(s) to the Commercial Software,
191+
which represent, as a whole, an original work of authorship.
192+
193+
6.5 "License" means a limited, non-exclusive, non-transferable, fully paid up,
194+
royalty free, right and license, without the right to grant or authorize
195+
sublicenses, solely for Your internal business operations to (i) install and
196+
use the applicable Features and Functions of the Elastic Software in Object
197+
Code, and (ii) permit Contractors and Your Affiliates to use the Elastic
198+
software as set forth in (i) above, provided that such use by Contractors must
199+
be solely for Your benefit and/or the benefit of Your Affiliates, and You
200+
shall be responsible for all acts and omissions of such Contractors and
201+
Affiliates in connection with their use of the Elastic software that are
202+
contrary to the terms and conditions of this Agreement.
203+
204+
6.6 "License Key" means a sequence of bytes, including but not limited to a
205+
JSON blob, that is used to enable certain features and functions of the
206+
Elastic Software.
207+
208+
6.7 "Marks and Notices" means all Elastic trademarks, trade names, logos and
209+
notices present on the Documentation as originally provided by Elastic.
210+
211+
6.8 "Non-production Environment" means an environment for development, testing
212+
or quality assurance, where software is not used for production purposes.
213+
214+
6.9 "Object Code" means any form resulting from mechanical transformation or
215+
translation of Source Code form, including but not limited to compiled object
216+
code, generated documentation, and conversions to other media types.
217+
218+
6.10 "Source Code" means the preferred form of computer software for making
219+
modifications, including but not limited to software source code,
220+
documentation source, and configuration files.
221+
222+
6.11 "Subscription" means the right to receive Support Services and a License
223+
to the Commercial Software.

Makefile

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
COMMIT=$(shell git rev-parse --short HEAD)
2+
VERSION ?= $(shell head -n 1 VERSION 2> /dev/null || echo "0.0.0")
3+
BUILD=$(shell date +%FT%T%z)
4+
LDFLAGS=-w -s -X main.Version=${VERSION} -X main.Build=${BUILD}
5+
PACKAGE_PATH=./build/package/
6+
DOCKER_BUILD=@export DOCKER_CONTENT_TRUST=1 && export DOCKER_BUILDKIT=1 && docker build --build-arg COMMIT='$(COMMIT)' --build-arg VERSION='$(VERSION)' --build-arg LDFLAGS='$(LDFLAGS)' -f $(PACKAGE_PATH)Dockerfile
7+
8+
CMD_COLOR_ON=\033[32m\xE2\x9c\x93
9+
CMD_COLOR_OFF=\033[0m
10+
11+
12+
.PHONY: help
13+
help: ## - Show help message
14+
@printf "${CMD_COLOR_ON} usage: make [target]\n\n${CMD_COLOR_OFF}"
15+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
16+
17+
18+
.PHONY: rpm
19+
rpm: ## - Build x86_64 linux RPM
20+
@printf "${CMD_COLOR_ON} Build rpm\n${CMD_COLOR_OFF}"
21+
@${DOCKER_BUILD} --ssh default --target rpm -o ./ .
22+
23+
.PHONY: image
24+
image: ## - Build the elastic fleet docker images
25+
@printf "${CMD_COLOR_ON} Build the elastic fleet docker image\n${CMD_COLOR_OFF}"
26+
${DOCKER_BUILD} --ssh default --target fleet -t fleet .
27+
28+
.PHONY: run
29+
run: image ## - Run the smallest and secured golang docker image based on scratch
30+
@printf "${CMD_COLOR_ON} Run the elastic fleet docker image\n${CMD_COLOR_OFF}"
31+
@docker-compose -f ./build/package/docker-compose.yml up
32+
33+
34+
.PHONY: local
35+
local: ## - Build packages using local environment
36+
@printf "${CMD_COLOR_ON} Build binaries using local go installation\n${CMD_COLOR_OFF}"
37+
go build -ldflags="${LDFLAGS}" -o ./bin/fleet ./cmd/fleet/
38+
@printf "${CMD_COLOR_ON} Binaries in ./bin/\n${CMD_COLOR_OFF}"
39+
40+
41+
.PHONY: clean
42+
clean: ## - Clean up build artifacts
43+
@printf "${CMD_COLOR_ON} Clean up build artifacts\n${CMD_COLOR_OFF}"
44+
rm -rf ./bin/ *.rpm
45+
46+

VERSION

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.0.14

cmd/fleet/auth.go

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// Licensed to Elasticsearch B.V. under one or more contributor
2+
// license agreements. See the NOTICE file distributed with
3+
// this work for additional information regarding copyright
4+
// ownership. Elasticsearch B.V. licenses this file to you under
5+
// the Apache License, Version 2.0 (the "License"); you may
6+
// not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package main
19+
20+
import (
21+
"errors"
22+
"net/http"
23+
"time"
24+
25+
"fleet/internal/pkg/apikey"
26+
"fleet/internal/pkg/env"
27+
"fleet/internal/pkg/saved"
28+
"github.com/elastic/go-elasticsearch/v8"
29+
"github.com/rs/zerolog/log"
30+
)
31+
32+
var kApiKeyTTL = env.ApiKeyTTL(time.Second * 5)
33+
var ErrApiKeyNotEnabled = errors.New("APIKey not enabled")
34+
35+
func authApiKey(r *http.Request, client *elasticsearch.Client) (*apikey.ApiKey, error) {
36+
37+
key, err := apikey.ExtractAPIKey(r)
38+
if err != nil {
39+
return nil, err
40+
}
41+
42+
if gCache.ValidApiKey(*key) {
43+
return key, nil
44+
}
45+
46+
start := time.Now()
47+
48+
info, err := key.Authenticate(r.Context(), client)
49+
50+
if err != nil {
51+
log.Error().
52+
Err(err).
53+
Dur("tdiff", time.Since(start)).
54+
Msg("ApiKey fail authentication")
55+
return nil, err
56+
}
57+
58+
log.Trace().
59+
Str("id", key.Id).
60+
Dur("tdiff", time.Since(start)).
61+
Str("UserName", info.UserName).
62+
Strs("Roles", info.Roles).
63+
Bool("enabled", info.Enabled).
64+
RawJSON("meta", info.Metadata).
65+
Msg("ApiKey authenticated")
66+
67+
if info.Enabled {
68+
gCache.SetApiKey(*key, kApiKeyTTL)
69+
} else {
70+
err = ErrApiKeyNotEnabled
71+
}
72+
73+
return key, err
74+
}
75+
76+
func authAgent(r *http.Request, id string, sv saved.CRUD) (*Agent, error) {
77+
// authenticate
78+
key, err := authApiKey(r, sv.Client())
79+
if err != nil {
80+
return nil, err
81+
}
82+
83+
agent, err := findAgentByApiKeyId(r.Context(), sv, key.Id)
84+
if err != nil {
85+
return nil, err
86+
}
87+
88+
// validate key alignment
89+
if agent.AccessApiKeyId != key.Id {
90+
log.Debug().
91+
Err(ErrAgentCorrupted).
92+
Interface("agent", &agent).
93+
Str("key.Id", key.Id).
94+
Msg("agent id mismatch")
95+
return nil, ErrAgentCorrupted
96+
}
97+
98+
return agent, nil
99+
}

0 commit comments

Comments
 (0)