@@ -92,19 +92,6 @@ def response(data=None, code=200, headers=None, raw=False):
92
92
return flask .current_app .make_response ((data , code , h ))
93
93
94
94
95
- def check_session ():
96
- session = flask .session
97
- if not session :
98
- logger .debug ('check_session: Session is empty' )
99
- return False
100
- if 'from' in session and get_remote_ip () != session ['from' ]:
101
- logger .debug ('check_session: Wrong source ip address' )
102
- session .clear ()
103
- return False
104
- # Session is valid
105
- return session .get ('auth' ) is True
106
-
107
-
108
95
def validate_parent_access (parent_id ):
109
96
cfg = config .load ()
110
97
if cfg .standalone :
@@ -120,7 +107,7 @@ def validate_parent_access(parent_id):
120
107
if index_endpoint is None :
121
108
index_endpoint = 'https://index.docker.io'
122
109
index_endpoint = index_endpoint .strip ('/' )
123
- url = '{0}/v1/images/{1}/{2}/{3}' .format (
110
+ url = '{0}/v1/images/{1}/{2}/layer/ {3}/access ' .format (
124
111
index_endpoint , full_repos_name [0 ], full_repos_name [1 ], parent_id
125
112
)
126
113
headers = {'Authorization' : flask .request .headers .get ('authorization' )}
@@ -228,7 +215,6 @@ def check_token(args):
228
215
# Token is valid, we create a session
229
216
session = flask .session
230
217
session ['repository' ] = auth .get ('repository' )
231
- session ['auth' ] = True
232
218
if is_ssl () is False :
233
219
# We enforce the IP check only when not using SSL
234
220
session ['from' ] = get_remote_ip ()
@@ -270,9 +256,12 @@ def parse_content_signature(s):
270
256
def requires_auth (f ):
271
257
@functools .wraps (f )
272
258
def wrapper (* args , ** kwargs ):
273
- if check_signature () is True or check_session () is True \
274
- or check_token (kwargs ) is True :
275
- return f (* args , ** kwargs )
259
+ session = flask .session
260
+ if check_signature () is True or check_token (kwargs ) is True :
261
+ if 'from' not in session or session ['from' ] == get_remote_ip ():
262
+ return f (* args , ** kwargs )
263
+ else :
264
+ session .clear ()
276
265
headers = {'WWW-Authenticate' : 'Token' }
277
266
return api_error ('Requires authorization' , 401 , headers )
278
267
return wrapper
0 commit comments