-
Notifications
You must be signed in to change notification settings - Fork 894
feat: peer wireguard #2445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat: peer wireguard #2445
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2361e15
feat: peer wireguard
coadler ccd4217
disable wireguard on agent tests
coadler b1805a2
fixup! disable wireguard on agent tests
coadler 2d53eaa
fixup! disable wireguard on agent tests
coadler c85a6e9
some stuff
coadler 05abed3
Add comments and minor renames to peerwg (#2609)
kylecarbs 14665de
change handshake separator
coadler 2591ffc
cleanup
coadler f7a827d
fixup! cleanup
coadler f22156e
Merge branch 'main' into colin/wireguard-peer
coadler faad97f
fix down migration
coadler File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
feat: peer wireguard
- Loading branch information
commit 2361e15d44367d5ddde98ed21dab14babf982bec
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package agent | ||
|
||
import ( | ||
"context" | ||
|
||
"golang.org/x/xerrors" | ||
"inet.af/netaddr" | ||
|
||
"cdr.dev/slog" | ||
"github.com/coder/coder/peer/peerwg" | ||
) | ||
|
||
func (a *agent) startWireguard(ctx context.Context, addrs []netaddr.IPPrefix) error { | ||
if a.wg != nil { | ||
_ = a.wg.Close() | ||
} | ||
|
||
if !a.enableWireguard { | ||
return nil | ||
} | ||
|
||
// We can't create a wireguard network without these. | ||
if len(addrs) == 0 || a.listenWireguardPeers == nil || a.postKeys == nil { | ||
return xerrors.New("wireguard is enabled, but no addresses were provided or necessary functions were not provided") | ||
} | ||
|
||
wg, err := peerwg.NewWireguardNetwork(ctx, a.logger.Named("wireguard"), addrs) | ||
if err != nil { | ||
return xerrors.Errorf("create wireguard network: %w", err) | ||
} | ||
|
||
err = a.postKeys(ctx, PublicKeys{ | ||
Public: wg.Private.Public(), | ||
Disco: wg.Disco, | ||
}) | ||
if err != nil { | ||
a.logger.Warn(ctx, "post keys", slog.Error(err)) | ||
} | ||
|
||
go func() { | ||
for { | ||
ch, listenClose, err := a.listenWireguardPeers(ctx, a.logger) | ||
if err != nil { | ||
a.logger.Warn(ctx, "listen wireguard peers", slog.Error(err)) | ||
return | ||
} | ||
|
||
for { | ||
peer := <-ch | ||
if peer == nil { | ||
break | ||
} | ||
|
||
err := wg.AddPeer(*peer) | ||
a.logger.Info(ctx, "added wireguard peer", slog.F("peer", peer.Public.ShortString()), slog.Error(err)) | ||
} | ||
|
||
listenClose() | ||
} | ||
}() | ||
|
||
a.wg = wg | ||
return nil | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.