Skip to content

Commit 164d495

Browse files
Merge pull request #13818 from rabbitmq/rabbitmq-server-13767
By @aaron-seo: Adds a new auth backend that only accepts loopback connections
2 parents c9b2b7f + 85e14c7 commit 164d495

19 files changed

+1154
-8
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ elvis
3737
!/deps/rabbitmq_amqp_client/
3838
!/deps/rabbitmq_auth_backend_cache/
3939
!/deps/rabbitmq_auth_backend_http/
40+
!/deps/rabbitmq_auth_backend_internal_loopback/
4041
!/deps/rabbitmq_auth_backend_ldap/
4142
!/deps/rabbitmq_auth_backend_oauth2/
4243
!/deps/rabbitmq_auth_mechanism_ssl/

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,7 @@ TIER1_PLUGINS := \
523523
rabbitmq_amqp1_0 \
524524
rabbitmq_auth_backend_cache \
525525
rabbitmq_auth_backend_http \
526+
rabbitmq_auth_backend_internal_loopback \
526527
rabbitmq_auth_backend_ldap \
527528
rabbitmq_auth_backend_oauth2 \
528529
rabbitmq_auth_mechanism_ssl \

deps/rabbit/src/rabbit_auth_mechanism_plain.erl

+19-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010

1111
-export([description/0, should_offer/1, init/1, handle_response/2]).
1212

13+
-record(state, {
14+
socket
15+
}).
16+
1317
-rabbit_boot_step({?MODULE,
1418
[{description, "auth mechanism plain"},
1519
{mfa, {rabbit_registry, register,
@@ -26,8 +30,17 @@ description() ->
2630
should_offer(_Sock) ->
2731
true.
2832

29-
init(_Sock) ->
30-
[].
33+
init(Sock) ->
34+
#state{socket = Sock}.
35+
36+
handle_response(Response, #state{socket = Socket}) ->
37+
case extract_user_pass(Response) of
38+
{ok, User, Pass} ->
39+
AuthProps = build_auth_props(Pass, Socket),
40+
rabbit_access_control:check_user_login(User, AuthProps);
41+
error ->
42+
{protocol_error, "response ~tp invalid", [Response]}
43+
end;
3144

3245
handle_response(Response, _State) ->
3346
case extract_user_pass(Response) of
@@ -37,6 +50,10 @@ handle_response(Response, _State) ->
3750
{protocol_error, "response ~tp invalid", [Response]}
3851
end.
3952

53+
54+
build_auth_props(Pass, Socket) ->
55+
[{password, Pass}, {sockOrAddr, Socket}].
56+
4057
extract_user_pass(Response) ->
4158
case extract_elem(Response) of
4259
{ok, User, Response1} ->

deps/rabbitmq_auth_backend_http/src/rabbit_auth_backend_http.erl

+6-2
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,13 @@ is_internal_property(_Other) -> false.
7979
is_internal_none_password(password, none) -> true;
8080
is_internal_none_password(_, _) -> false.
8181

82+
is_sockOrAddr(sockOrAddr) -> true;
83+
is_sockOrAddr(_) -> false.
84+
8285
extract_other_credentials(AuthProps) ->
83-
PublicAuthProps = [{K,V} || {K,V} <-AuthProps, not is_internal_property(K) and
84-
not is_internal_none_password(K, V)],
86+
PublicAuthProps = [{K,V} || {K,V} <-AuthProps, not is_internal_property(K) and
87+
not is_internal_none_password(K, V) and
88+
not is_sockOrAddr(K)],
8589
case PublicAuthProps of
8690
[] -> resolve_using_persisted_credentials(AuthProps);
8791
_ -> PublicAuthProps
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test/config_schema_SUITE_data/schema/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Contributor Code of Conduct
2+
3+
As contributors and maintainers of this project, and in the interest of fostering an open
4+
and welcoming community, we pledge to respect all people who contribute through reporting
5+
issues, posting feature requests, updating documentation, submitting pull requests or
6+
patches, and other activities.
7+
8+
We are committed to making participation in this project a harassment-free experience for
9+
everyone, regardless of level of experience, gender, gender identity and expression,
10+
sexual orientation, disability, personal appearance, body size, race, ethnicity, age,
11+
religion, or nationality.
12+
13+
Examples of unacceptable behavior by participants include:
14+
15+
* The use of sexualized language or imagery
16+
* Personal attacks
17+
* Trolling or insulting/derogatory comments
18+
* Public or private harassment
19+
* Publishing other's private information, such as physical or electronic addresses,
20+
without explicit permission
21+
* Other unethical or unprofessional conduct
22+
23+
Project maintainers have the right and responsibility to remove, edit, or reject comments,
24+
commits, code, wiki edits, issues, and other contributions that are not aligned to this
25+
Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors
26+
that they deem inappropriate, threatening, offensive, or harmful.
27+
28+
By adopting this Code of Conduct, project maintainers commit themselves to fairly and
29+
consistently applying these principles to every aspect of managing this project. Project
30+
maintainers who do not follow or enforce the Code of Conduct may be permanently removed
31+
from the project team.
32+
33+
This Code of Conduct applies both within project spaces and in public spaces when an
34+
individual is representing the project or its community.
35+
36+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by
37+
contacting a project maintainer at [[email protected]](mailto:[email protected]). All complaints will
38+
be reviewed and investigated and will result in a response that is deemed necessary and
39+
appropriate to the circumstances. Maintainers are obligated to maintain confidentiality
40+
with regard to the reporter of an incident.
41+
42+
This Code of Conduct is adapted from the
43+
[Contributor Covenant](https://contributor-covenant.org), version 1.3.0, available at
44+
[contributor-covenant.org/version/1/3/0/](https://contributor-covenant.org/version/1/3/0/)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
## Overview
2+
3+
RabbitMQ projects use pull requests to discuss, collaborate on and accept code contributions.
4+
Pull requests is the primary place of discussing code changes.
5+
6+
## How to Contribute
7+
8+
The process is fairly standard:
9+
10+
* Present your idea to the RabbitMQ core team using [GitHub Discussions](https://github.com/rabbitmq/rabbitmq-server/discussions) or [RabbitMQ community Discord server](https://rabbitmq.com/discord)
11+
* Fork the repository or repositories you plan on contributing to
12+
* Run `git clean -xfffd && gmake clean && gmake distclean && gmake` to build all subprojects from scratch
13+
* Create a branch with a descriptive name
14+
* Make your changes, run tests, ensure correct code formatting, commit with a [descriptive message](https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html), push to your fork
15+
* Submit pull requests with an explanation what has been changed and **why**
16+
* Submit a filled out and signed [Contributor Agreement](https://cla.pivotal.io/) if needed (see below)
17+
* Be patient. We will get to your pull request eventually
18+
19+
20+
## Running Tests
21+
22+
Test suites of individual subprojects can be run from the subproject directory under
23+
`deps/*`. For example, for the core broker:
24+
25+
``` shell
26+
# Running all server suites in parallel will take between 30 and 40 minutes on reasonably
27+
# recent multi-core machines. This is rarely necessary in development environments.
28+
# Running individual test suites or groups of test suites can be enough.
29+
#
30+
31+
# Before you start: this will terminate all running nodes, make processes and Common Test processes
32+
killall -9 beam.smp; killall -9 erl; killall -9 make; killall -9 epmd; killall -9 erl_setup_child; killall -9 ct_run
33+
34+
# the core broker subproject
35+
cd deps/rabbit
36+
37+
# cleans build artifacts
38+
git clean -xfffd
39+
gmake clean; gmake distclean
40+
41+
# builds the broker and all of its dependencies
42+
gmake
43+
# runs an integration test suite, tests/rabbit_fifo_SUITE with CT (Common Test)
44+
gmake ct-rabbit_fifo
45+
# runs an integration test suite, tests/quorum_queue_SUITE with CT (Common Test)
46+
gmake ct-quorum_queue
47+
# runs an integration test suite, tests/queue_parallel_SUITE with CT (Common Test)
48+
gmake ct-queue_parallel
49+
# runs a unit test suite tests/unit_log_management_SUITE with CT (Common Test)
50+
gmake ct-unit_log_management
51+
```
52+
53+
### Running Specific Groups or Tests
54+
55+
All `ct-*` Make targets support a `t=` argument which are transformed to [`-group` and `-case` Common Test runner options](https://www.erlang.org/doc/apps/common_test/run_test_chapter.html).
56+
57+
``` shell
58+
# Runs a a group of tests named 'all_tests_with_prefix' in suite 'test/rabbit_mgmt_http_SUITE.erl'
59+
gmake ct-rabbit_mgmt_http t="all_tests_with_prefix"
60+
61+
# Runs a test named 'users_test' in group 'all_tests_with_prefix' in suite 'test/rabbit_mgmt_http_SUITE.erl'
62+
gmake ct-rabbit_mgmt_http t="all_tests_with_prefix:users_test"
63+
# Runs a test named 'queues_test' in group 'all_tests_with_prefix' in suite 'test/rabbit_mgmt_http_SUITE.erl'
64+
gmake ct-rabbit_mgmt_http t="all_tests_with_prefix:queues_test"
65+
```
66+
67+
### Running Tests with a Specific Schema Data Store
68+
69+
Set `RABBITMQ_METADATA_STORE` to either `khepri` or `mnesia` to make the Common Test suites
70+
use a specific [schema data store]() (metadata store):
71+
72+
``` shell
73+
RABBITMQ_METADATA_STORE=khepri gmake ct-quorum_queue
74+
```
75+
76+
Or, with Nu shell:
77+
78+
```nu
79+
with-env {'RABBITMQ_METADATA_STORE': 'khepri'} { gmake ct-quorum_queue }
80+
```
81+
82+
83+
## Running Single Nodes from Source
84+
85+
``` shell
86+
# Run from repository root.
87+
# Starts a node with the management plugin enabled
88+
gmake run-broker RABBITMQ_PLUGINS=rabbitmq_management
89+
```
90+
91+
The nodes will be started in the background. They will use `rabbit@{hostname}` for its name, so CLI will be able to contact
92+
it without an explicit `-n` (`--node`) argument:
93+
94+
```shell
95+
# Run from repository root.
96+
./sbin/rabbitmq-diagnostics status
97+
```
98+
99+
## Running Clusters from Source
100+
101+
``` shell
102+
# Run from repository root.
103+
# Starts a three node cluster with the management plugin enabled
104+
gmake start-cluster NODES=3 RABBITMQ_PLUGINS=rabbitmq_management
105+
```
106+
107+
The node will use `rabbit-{n}@{hostname}` for names, so CLI must
108+
be explicitly given explicit an `-n` (`--node`) argument in order to
109+
contact one of the nodes:
110+
111+
* `rabbit-1`
112+
* `rabbit-2`
113+
* `rabbit-3`
114+
115+
The names of the nodes can be looked up via
116+
117+
``` shell
118+
epmd -names
119+
```
120+
121+
``` shell
122+
# Run from repository root.
123+
# Makes CLI tools talk to node rabbit-2
124+
sbin/rabbitmq-diagnostics cluster_status -n rabbit-2
125+
126+
# Run from repository root.
127+
# Makes CLI tools talk to node rabbit-1
128+
sbin/rabbitmq-diagnostics status -n rabbit-1
129+
```
130+
131+
To stop a previously started cluster:
132+
133+
``` shell
134+
# Run from repository root.
135+
# Stops a three node cluster started earlier
136+
gmake stop-cluster NODES=3
137+
```
138+
139+
140+
## Working on Management UI with BrowserSync
141+
142+
When working on management UI code, besides starting the node with
143+
144+
``` shell
145+
# starts a node with the management plugin enabled
146+
gmake run-broker RABBITMQ_PLUGINS=rabbitmq_management
147+
```
148+
149+
(or any other set of plugins), it is highly recommended to use [BrowserSync](https://browsersync.io/#install)
150+
to shorten the edit/feedback cycle for JS files, CSS, and so on.
151+
152+
First, install BrowserSync using NPM:
153+
154+
``` shell
155+
npm install -g browser-sync
156+
```
157+
158+
Assuming a node running locally with HTTP API on port `15672`, start
159+
a BrowserSync proxy like so:
160+
161+
``` shell
162+
cd deps/rabbitmq_management/priv/www
163+
164+
browser-sync start --proxy localhost:15672 --serverStatic . --files .
165+
```
166+
167+
BrowserSync will automatically open a browser window for you to use. The window
168+
will automatically refresh when one of the static (templates, JS, CSS) files change.
169+
170+
All HTTP requests that BrowserSync does not know how to handle will be proxied to
171+
the HTTP API at `localhost:15672`.
172+
173+
174+
## Formatting the RabbitMQ CLI
175+
176+
The RabbitMQ CLI uses the standard [Elixir code formatter](https://hexdocs.pm/mix/main/Mix.Tasks.Format.html). To ensure correct code formatting of the CLI:
177+
178+
```
179+
cd deps/rabbitmq_cli
180+
mix format
181+
```
182+
183+
Running `make` will validate the CLI formatting and issue any necessary warnings. Alternatively, run the format checker in the `deps/rabbitmq_cli` directory:
184+
185+
```
186+
mix format --check-formatted
187+
```
188+
189+
## Code of Conduct
190+
191+
See [CODE_OF_CONDUCT.md](./CODE_OF_CONDUCT.md).
192+
193+
## Contributor Agreement
194+
195+
If you want to contribute a non-trivial change, please submit a signed copy of our
196+
[Contributor Agreement](https://cla.pivotal.io/) around the time
197+
you submit your pull request. This will make it much easier (in some cases, possible)
198+
for the RabbitMQ team at Pivotal to merge your contribution.
199+
200+
## Where to Ask Questions
201+
202+
If something isn't clear, feel free to ask on [GitHub Discussions](https://github.com/rabbitmq/rabbitmq-server/discussions)
203+
and [community Discord server](https://rabbitmq.com/discord).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This package is licensed under the MPL 2.0. For the MPL 2.0, please see LICENSE-MPL-RabbitMQ.
2+
3+
If you have any questions regarding licensing, please contact us at [email protected].

0 commit comments

Comments
 (0)