Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
server
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
m-team
oidc
mytoken
server
Commits
1b6ecd90
Commit
1b6ecd90
authored
3 years ago
by
Gabriel Zachmann
Browse files
Options
Downloads
Patches
Plain Diff
fix ip restrictions if two subnets are used
parent
c82a1dc2
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
CHANGELOG.md
+4
-0
4 additions, 0 deletions
CHANGELOG.md
shared/utils/utils.go
+25
-7
25 additions, 7 deletions
shared/utils/utils.go
with
29 additions
and
7 deletions
CHANGELOG.md
+
4
−
0
View file @
1b6ecd90
...
...
@@ -28,6 +28,10 @@
-
Removed buttons from webinterface in the tokeninfo tabs. The content now loads directly when switching the tab.
-
Added request ids to response header and logging
### Bugfixes
-
Fixed a bug where restrictions did not behave correctly when multiple subnets were used
## mytoken 0.3.2
-
Fixed password prompt for migratedb
...
...
This diff is collapsed.
Click to expand it.
shared/utils/utils.go
+
25
−
7
View file @
1b6ecd90
package
utils
import
(
"bytes"
"encoding/base64"
"fmt"
"math/rand"
...
...
@@ -99,22 +100,39 @@ func IPsAreSubSet(ipsA, ipsB []string) bool {
return
true
}
func
parseIP
(
ip
string
)
(
net
.
IP
,
*
net
.
IPNet
)
{
ipA
,
ipNet
,
err
:=
net
.
ParseCIDR
(
ip
)
if
err
!=
nil
{
ipA
=
net
.
ParseIP
(
ip
)
}
if
ipNet
!=
nil
&&
!
ipA
.
Equal
(
ipNet
.
IP
)
{
ipNet
=
nil
}
return
ipA
,
ipNet
}
// IPIsIn checks if a ip is in a slice of ips, it will also check ip subnets
func
IPIsIn
(
ip
string
,
ips
[]
string
)
bool
{
if
len
(
ips
)
==
0
{
return
false
}
ipA
:=
net
.
P
arseIP
(
ip
)
ipA
,
ipNetA
:=
p
arseIP
(
ip
)
for
_
,
ipp
:=
range
ips
{
if
strings
.
Contains
(
ipp
,
"/"
)
{
_
,
ipNetB
,
_
:=
net
.
ParseCIDR
(
ipp
)
if
ipNetB
!=
nil
&&
ipNetB
.
Contains
(
ipA
)
{
ipB
,
ipNetB
:=
parseIP
(
ipp
)
if
ipNetA
==
nil
&&
ipNetB
==
nil
{
if
ipA
.
Equal
(
ipB
)
{
return
true
}
}
else
if
ipNetA
==
nil
&&
ipNetB
!=
nil
{
if
ipNetB
.
Contains
(
ipA
)
{
return
true
}
}
else
if
ipNetA
!=
nil
&&
ipNetB
!=
nil
{
if
ipNetB
.
Contains
(
ipA
)
&&
bytes
.
Compare
(
ipNetA
.
Mask
,
ipNetB
.
Mask
)
>=
0
{
return
true
}
}
else
if
ip
==
ipp
{
return
true
}
// check for ipNetA != nil && ipNetB == nil not needed -> won't work
}
return
false
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment