Hi @stephen.schaff ,
The code "looks" okay to me (similar to that reference script we have), but obviously I didn't or test it.
I know you double-checked the token you're using, but that's the only way I can see that 403 being raised. I suppose the ProGetRegistry could also be wrong.
But according to the code, there are only 4 cases where that 403 error (i.e. DockerException.Denied()') can occur on the auth handler, and only one of those hit with a Basic api:abc123 header.
I shared the code below.
private static Task ProcessAuthAsync(AhHttpContext context)
{
// do not allow the response to be stored on shared caches
context.Response.AddCacheResponseHeaders(HttpCacheability.Private);
var authHeader = context.Request.Headers["Authorization"];
if (string.IsNullOrWhiteSpace(authHeader) || !authHeader.StartsWith("Basic ", StringComparison.OrdinalIgnoreCase))
{
if (string.IsNullOrEmpty(context.Request.QueryString["scope"]) || !string.IsNullOrEmpty(context.Request.QueryString["account"]))
{
context.Response.AppendHeader("WWW-Authenticate", "basic");
context.Response.StatusCode = 401;
return Task.CompletedTask;
}
context.Response.StatusCode = 200;
context.Response.ContentType = "application/json";
using var jsonWriter = new JsonTextWriter(context.Response.Output);
jsonWriter.WriteStartObject();
jsonWriter.WritePropertyName("token");
jsonWriter.WriteValue("anonymous");
jsonWriter.WriteEndObject();
return Task.CompletedTask;
}
var basicAuthToken = InedoLib.UTF8Encoding.GetString(Convert.FromBase64String(authHeader.Substring("Basic ".Length).Trim()));
var userPass = basicAuthToken.Split(new[] { ':' }, 2);
if (userPass.Length != 2)
throw DockerException.Denied();
string validatedUserToken;
if (string.Equals(userPass[0], "api", StringComparison.OrdinalIgnoreCase))
{
try { WebApiContext.CreateFromKey(context, userPass[1]); }
catch { throw DockerException.Denied(); }
validatedUserToken = basicAuthToken;
}
else
{
if (!LicensingInformation.IsFreeEditionEdgeNodeOrInvalid && !ProGetConfig.Web.UsernamePasswordAuthenticationEnabled)
throw DockerException.Denied();
if (WebSecurity.GetUser(userPass[0], userPass[1]) == null)
throw DockerException.Denied();
validatedUserToken = userPass[0];
}
var ticket = new AhAuthenticationTicket(1, "docker-bearer", DateTime.UtcNow, DateTime.UtcNow.AddHours(1), true, validatedUserToken);
context.Response.StatusCode = 200;
context.Response.ContentType = "application/json";
using (var jsonWriter = new JsonTextWriter(context.Response.Output))
{
jsonWriter.WriteStartObject();
jsonWriter.WritePropertyName("token");
jsonWriter.WriteValue(AhAuthentication.Encrypt(ticket));
jsonWriter.WritePropertyName("expires_in");
jsonWriter.WriteValue((int)(ticket.Expiration - ticket.IssueDate).TotalSeconds);
jsonWriter.WritePropertyName("issued_at");
jsonWriter.WriteValue(ticket.IssueDate);
jsonWriter.WriteEndObject();
}
return Task.CompletedTask;
}
Hope that helps. I would try to trigger other error conditions in the code to help preserve your sanity.
Thanks,
Alana