AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题

问题[authorization](server)

Martin Hope
Major Kuprich
Asked: 2021-10-01 10:21:08 +0800 CST

带有基本身份验证的清漆返回 401

  • 1

我尝试使用以下解决方案在具有基本身份验证身份验证的服务器上配置 Varnish:

  • https://stackoverflow.com/a/40424168/7202171
  • https://blog.tenya.me/blog/2011/12/14/varnish-http-authentication/#comment-2882579903

但这无济于事。Varnish 日志仍然显示 401 错误:

varnishlog -g raw -i Backend_health

         0 Backend_health - mag2.default Still sick 4--X-R- 0 5 10 0.001574 0.000000 HTTP/1.1 401 Unauthorized

我的清漆配置(4.0 版):

vcl 4.0;

import std;
# The minimal Varnish version is 4.0
# For SSL offloading, pass the following header in your proxy server or load balancer: 'X-Forwarded-Proto: https'

backend default {
    .host = "127.0.0.1";
    .port = "8080";
    .first_byte_timeout = 600s;
    .probe = {
        .url = "/health_check.php";
        .timeout = 2s;
        .interval = 5s;
        .window = 10;
        .threshold = 5;
   }
}

acl purge {
    "localhost";
}

sub vcl_recv {
    if (! req.http.Authorization ~ "Basic ZGV2OmRldg=") {
    return(synth(401, "Restricted"));
    }

    if (req.method == "PURGE") {
        if (client.ip !~ purge) {
            return (synth(405, "Method not allowed"));
        }
        # To use the X-Pool header for purging varnish during automated deployments, make sure the X-Pool header
        # has been added to the response in your backend server config. This is used, for example, by the
        # capistrano-magento2 gem for purging old content from varnish during it's deploy routine.
        if (!req.http.X-Magento-Tags-Pattern && !req.http.X-Pool) {
            return (synth(400, "X-Magento-Tags-Pattern or X-Pool header required"));
        }
        if (req.http.X-Magento-Tags-Pattern) {
          ban("obj.http.X-Magento-Tags ~ " + req.http.X-Magento-Tags-Pattern);
        }
        if (req.http.X-Pool) {
          ban("obj.http.X-Pool ~ " + req.http.X-Pool);
        }
        return (synth(200, "Purged"));
    }

    if (req.method != "GET" &&
        req.method != "HEAD" &&
        req.method != "PUT" &&
        req.method != "POST" &&
        req.method != "TRACE" &&
        req.method != "OPTIONS" &&
        req.method != "DELETE") {
          /* Non-RFC2616 or CONNECT which is weird. */
          return (pipe);
    }

    # We only deal with GET and HEAD by default
    if (req.method != "GET" && req.method != "HEAD") {
        return (pass);
    }

    # Bypass shopping cart and checkout
    if (req.url ~ "/checkout") {
        return (pass);
    }

    # Bypass health check requests
    if (req.url ~ "/pub/health_check.php") {
        return (pass);
    }

    # Set initial grace period usage status
    set req.http.grace = "none";

    # normalize url in case of leading HTTP scheme and domain
    set req.url = regsub(req.url, "^http[s]?://", "");

    # collect all cookies
    std.collect(req.http.Cookie);

    # Compression filter. See https://www.varnish-cache.org/trac/wiki/FAQ/Compression
    if (req.http.Accept-Encoding) {
        if (req.url ~ "\.(jpg|jpeg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|swf|flv)$") {
            # No point in compressing these
            unset req.http.Accept-Encoding;
        } elsif (req.http.Accept-Encoding ~ "gzip") {
            set req.http.Accept-Encoding = "gzip";
        } elsif (req.http.Accept-Encoding ~ "deflate" && req.http.user-agent !~ "MSIE") {
            set req.http.Accept-Encoding = "deflate";
        } else {
            # unknown algorithm
            unset req.http.Accept-Encoding;
        }
    }

    # Remove all marketing get parameters to minimize the cache objects
    if (req.url ~ "(\?|&)(gclid|cx|ie|cof|siteurl|zanpid|origin|fbclid|mc_[a-z]+|utm_[a-z]+|_bta_[a-z]+)=") {
        set req.url = regsuball(req.url, "(gclid|cx|ie|cof|siteurl|zanpid|origin|fbclid|mc_[a-z]+|utm_[a-z]+|_bta_[a-z]+)=[-_A-z0-9+()%.]+&?", "");
        set req.url = regsub(req.url, "[?|&]+$", "");
    }

    # Static files caching
    if (req.url ~ "^/(pub/)?(media|static)/") {
        # Static files should not be cached by default
        return (pass);

        # But if you use a few locales and don't use CDN you can enable caching static files by commenting previous line (#return (pass);) and uncommenting next 3 lines
        #unset req.http.Https;
        #unset req.http.X-Forwarded-Proto;
        #unset req.http.Cookie;
    }

     # Authenticated GraphQL requests should not be cached by default
    if (req.url ~ "/graphql" && req.http.Authorization ~ "^Bearer") {
        return (pass);
    }

unset req.http.Authorization;
    return (hash);
}

sub vcl_hash {
    if (req.http.cookie ~ "X-Magento-Vary=") {
        hash_data(regsub(req.http.cookie, "^.*?X-Magento-Vary=([^;]+);*.*$", "\1"));
    }

    if (req.url ~ "/graphql") {
        call process_graphql_headers;
    }

    # To make sure http users don't see ssl warning
    if (req.http.X-Forwarded-Proto) {
        hash_data(req.http.X-Forwarded-Proto);
    }
    
}

sub process_graphql_headers {
    if (req.http.Store) {
        hash_data(req.http.Store);
    }
    if (req.http.Content-Currency) {
        hash_data(req.http.Content-Currency);
    }
}

sub vcl_backend_fetch {
    # auth with admin:admin
    set bereq.http.Authorization = "Basic ZGV2OmRldg==";
}

sub vcl_backend_response {

    set beresp.grace = 3d;

    if (beresp.http.content-type ~ "text") {
        set beresp.do_esi = true;
    }

    if (bereq.url ~ "\.js$" || beresp.http.content-type ~ "text") {
        set beresp.do_gzip = true;
    }

    if (beresp.http.X-Magento-Debug) {
        set beresp.http.X-Magento-Cache-Control = beresp.http.Cache-Control;
    }

    # cache only successfully responses and 404s
    if (beresp.status != 200 && beresp.status != 404) {
        set beresp.ttl = 0s;
        set beresp.uncacheable = true;
        return (deliver);
    } elsif (beresp.http.Cache-Control ~ "private") {
        set beresp.uncacheable = true;
        set beresp.ttl = 86400s;
        return (deliver);
    }

    # validate if we need to cache it and prevent from setting cookie
    if (beresp.ttl > 0s && (bereq.method == "GET" || bereq.method == "HEAD")) {
        unset beresp.http.set-cookie;
    }

   # If page is not cacheable then bypass varnish for 2 minutes as Hit-For-Pass
   if (beresp.ttl <= 0s ||
       beresp.http.Surrogate-control ~ "no-store" ||
       (!beresp.http.Surrogate-Control &&
       beresp.http.Cache-Control ~ "no-cache|no-store") ||
       beresp.http.Vary == "*") {
       # Mark as Hit-For-Pass for the next 2 minutes
        set beresp.ttl = 120s;
        set beresp.uncacheable = true;
    }

    return (deliver);
}

sub vcl_deliver {
    if (resp.http.X-Magento-Debug) {
        if (resp.http.x-varnish ~ " ") {
            set resp.http.X-Magento-Cache-Debug = "HIT";
            set resp.http.Grace = req.http.grace;
        } else {
            set resp.http.X-Magento-Cache-Debug = "MISS";
        }
    } else {
        unset resp.http.Age;
    }

    # Not letting browser to cache non-static files.
    if (resp.http.Cache-Control !~ "private" && req.url !~ "^/(pub/)?(media|static)/") {
        set resp.http.Pragma = "no-cache";
        set resp.http.Expires = "-1";
        set resp.http.Cache-Control = "no-store, no-cache, must-revalidate, max-age=0";
    }

    unset resp.http.X-Magento-Debug;
    unset resp.http.X-Magento-Tags;
    unset resp.http.X-Powered-By;
    unset resp.http.Server;
    unset resp.http.X-Varnish;
    unset resp.http.Via;
    unset resp.http.Link;
}

sub vcl_hit {
    if (obj.ttl >= 0s) {
        # Hit within TTL period
        return (deliver);
    }
    if (std.healthy(req.backend_hint)) {
        if (obj.ttl + 300s > 0s) {
            # Hit after TTL expiration, but within grace period
            set req.http.grace = "normal (healthy server)";
            return (deliver);
        } else {
            # Hit after TTL and grace expiration
            return (fetch);
        }
    } else {
        # server is not healthy, retrieve from cache
        set req.http.grace = "unlimited (unhealthy server)";
        return (deliver);
    }
}

sub vcl_synth {
  if (resp.status == 401) {
    set resp.status = 401;
    set resp.http.WWW-Authenticate = "Basic";
    return(deliver);
  }
}
magento nginx varnish http-basic-authentication authorization
  • 1 个回答
  • 570 Views
Martin Hope
droplet
Asked: 2021-07-09 08:48:56 +0800 CST

NGINX auth_basic 排除对特定 php 脚本的 GET 请求

  • 1

我似乎无法弄清楚如何从 auth_basic 中排除特定位置。

server {
        server_name example.com;

        root /var/www/html;

        index index.php;

        auth_basic "Nein nein nein";
        auth_basic_user_file .htpasswd;

        location / {
                try_files $uri $uri/ =404;
        }

        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        }

        # this script needs free access and takes query string parameters
        location /sub/script.php {
                auth_basic off;
        }

        # this works fine
        location /sub/a-javascript.js {
                auth_basic off;
        }
...

位置 /sub/script.php 需要免费访问。如果它只能允许 GET 请求它也很好。我的问题似乎是它之后的查询参数。

总是使用许多查询参数来请求脚本 script.php?param=something&other_param=somethingelse&etc=etc

nginx php-fpm authorization
  • 1 个回答
  • 339 Views
Martin Hope
Cyberpks
Asked: 2021-05-30 20:22:33 +0800 CST

用于软件认证的硬件令牌/UUID

  • 1

每台计算机主板/BIOS 上是否有唯一的硬件令牌或 UUID 可用于创建“强耦合”软件?

我正在为客户编写专有软件,但我买不起任何人来创建相同的副本,因为未经授权的复制和安装会导致整个设置出现故障,从而导致生命和财产损失。该设置适用于 LAN 上的多个硬件设备,每个设备都有自己的安全密钥,并创建类似于“区块链”的设置。

我想知道主板上是否有特殊的硬件设备/IC(如 BIOS),这对于世界上制造的所有计算机都是独一无二的?

我通读了几篇文章,并想出了以下替代方案:

  1. BIOS 具有唯一的序列号 - 问题:并非所有 BIOS 制造商都确保将序列号写入其芯片。我现在的电脑就是这样一个例子。主板制造商是MSI和 BIOS 生产的AMI。当查询时,我得到Default string结果。
  2. USB 令牌设备 - 问题:USB 设备是可拆卸的,它可以与软件一起轻松迁移到新系统。
  3. MAC 地址 - 问题:可以很容易地更改它。我不想让客户仅仅通过更换网卡而遇到麻烦。
  4. MFA(多因素身份验证) - 问题:LAN 将无法连接到 WWW,因此可能根本无法实现此功能。

有没有替代方案?我希望有一个强耦合系统,以便创建副本非常困难(如果不是不可能的话)。任何需要的维护只能由经过培训和授权的人员进行。

hardware security bios encryption authorization
  • 2 个回答
  • 112 Views
Martin Hope
rnoodle
Asked: 2021-02-05 09:20:04 +0800 CST

即使作为 root 用户,也无法在 Centos 7 中启动服务并出现错误“授权不可用”

  • 1

我无法为以下 Centos 7 服务器启动服务

[root@myserver home]# uname -r
3.10.0-1160.11.1.el7.x86_64
[root@myserver home]# cat /etc/centos-release
CentOS Linux release 7.9.2009 (Core)

当我观察到 docker 宕机时,我第一次意识到有问题,所以我以 root 身份运行以下命令

[root@myserver home]# systemctl start docker
 Authorization not available. Check if polkit service is running or see debug message for 
 more information.
 Failed to start docker.service: Connection timed out
 See system logs and 'systemctl status docker.service' for details.
[root@myserver home]# systemctl status docker.service
 ● docker.service - Docker Application Container Engine
 Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
 Active: inactive (dead)
 Docs: https://docs.docker.com

然后我跑了

 [root@myserver home]# systemctl | grep -i fail
 ● firewalld.service                          loaded failed     failed      firewalld - dynamic firewall daemon
 ● plymouth-start.service                     loaded failed     failed      Show Plymouth Boot Screen
 ● polkit.service                             loaded failed     failed      Authorization Manager
 ● systemd-machined.service                   loaded failed     failed      Virtual Machine and Container Registration Service
 ● tuned.service                              loaded failed     failed      Dynamic System Tuning Daemon

还

 [root@myserver home]# systemctl status polkit.service
 ● polkit.service - Authorization Manager
    Loaded: loaded (/usr/lib/systemd/system/polkit.service; static; vendor preset: enabled)
    Active: failed (Result: timeout) since Thu 2021-02-04 11:14:54 GMT; 5h 45min ago
      Docs: man:polkit(8)
   Process: 7932 ExecStart=/usr/lib/polkit-1/polkitd --no-debug (code=killed, signal=TERM)
  Main PID: 7932 (code=killed, signal=TERM)

  Feb 04 11:13:23 myserver.com systemd[1]: Starting Authorization Manager...
  Feb 04 11:13:48 myserver.com polkitd[7932]: Started polkitd version 0.112
  Feb 04 11:14:54 myserver.com systemd[1]: polkit.service start operation timed out. Terminating.
  Feb 04 11:14:54 myserver.com systemd[1]: Failed to start Authorization Manager.
  Feb 04 11:14:54 myserver.com systemd[1]: Unit polkit.service entered failed state.
  Feb 04 11:14:54 myserver.com systemd[1]: polkit.service failed.

我不知道对服务器进行的任何更新。我认为这些问题是在计划外重启后开始的,但我无法确定重启的原因。为什么启动授权管理器会超时?有人对进一步调查有什么建议吗?

centos service centos7 docker authorization
  • 2 个回答
  • 12384 Views
Martin Hope
deigeorgiev
Asked: 2020-11-10 01:05:53 +0800 CST

能够将身份验证参数/标头注入请求的代理服务器

  • 0

这个想法是有一个代理服务器(如 SOCKS4/5,但用于 HTTP 协议),该代理服务器的目的是通过操纵请求代表用户验证请求。

例如,假设组织有 AWS 环境。他们没有向工程师提供 AWS 的凭证,而是为他们提供了对 HTTP 代理的访问权限,他们将机器设置为将所有请求发送到代理,并且代理服务器将所需的 HTTP 标头注入到请求中。

经过一番研究,我无法找到类似的解决方案。您是否知道这样的解决方案,或能够满足上述要求的一组解决方案?

authentication proxy https authorization
  • 1 个回答
  • 103 Views
Martin Hope
Matteo Tassinari
Asked: 2020-04-28 05:22:50 +0800 CST

Apache 身份验证失败,需要 ldap-group

  • 0

我一直在尝试将 Windows 服务器上的 apache 绑定到我们的活动目录服务器以进行身份​​验证和授权。

为了测试它,我一直在尝试使用以下参数的“ldap-status”处理程序

<Location "/ldap-status">
    SetHandler ldap-status

    AuthType Basic
    AuthBasicProvider ldap
    AuthName "LDAP Status"
    LDAPReferrals off
    AuthLDAPBindAuthoritative on
    AuthLDAPURL "ldap://1.2.3.4:389/cn=Users,dc=XXX,dc=example,dc=com?sAMAccountName?sub?(objectClass=person)" NONE
    AuthLDAPGroupAttribute member
    AuthLDAPGroupAttributeIsDN on
    AuthLDAPMaxSubGroupDepth 0
    AuthLDAPBindDN xxx
    AuthLDAPBindPassword xxx
    Require ldap-group "cn=TEST GROUP,cn=Users,dc=XXX,dc=example,dc=com"
</Location>

到目前为止,如果我将其删除Require ldap-group并替换为Require valid-user,它可以正常工作,但如果我恢复组要求则无法正常工作。

从我使用 powershell 从 AD 服务器中可以看到,该组存在并且它具有member列出所有成员的 DN 的属性;基于此,我设置AuthLDAPGroupAttribute为member和。AuthLDAPGroupAttributeIsDNon

我确定我的用户在我需要检查的组中,但是在 apache 错误日志中只有这条记录,这并不能真正帮助理解原因:

[Mon Apr 27 14:52:08.023952 2020] [authz_core:error] [pid 13168:tid 2072] [client 10.0.1.45:59690] AH01631: user mtassinari: authorization failure for "/ldap-status":

What can I do to correct the configuration in order to understand why "require ldap-group" fails?

active-directory authentication ldap apache-2.4 authorization
  • 2 个回答
  • 1338 Views
Martin Hope
Mikhail T.
Asked: 2017-02-02 10:00:42 +0800 CST

如何告诉 Apache 回复 403 而不是 401?

  • 2

我们对 s 的子树有一些规则Location,包括Require-ingldap-group和expr-s。

用户受到适当的挑战,以提供经过验证的登录凭据。

但是,即使凭据正确并且由于其他原因(例如属于错误的组或来自不正确的 IP 地址)而拒绝访问,服务器的响应始终是 401,而不是 403。

结果,浏览器不断提示用户“再试一次”......我可以告诉 Apache(2.4)使用 403,如果Authorization-header 中提供的信息签出,并且它是其他一些规则,拒绝要求?

再次,我知道,为什么在身份验证成功后,某些用户的授权被拒绝 - 它应该是。我只需要与这些用户沟通,即:“是的,我们相信你就是你所说的那个人,但你不被允许访问这个位置。”

看来,mod_rewrite 是引发 403 响应的唯一方法—— mod_rewrite 表达式是否可以检查 LDAP 组的成员资格或强制将状态从 401 更改为 403?

我在WebMaster 的网站上问过这个问题,但没有得到答案——那里的人似乎更注重内容。

这是我当前配置的相关片段:

<Location /foo>
         Require ldap-group CN=foo,OU=Groups,DC=example,DC=net
</Location>

当验证提供的用户名/密码,但不满足要求时,我需要返回 403... 401 当前正在返回。

mod-rewrite apache-2.4 http-status-code-403 authorization
  • 1 个回答
  • 1367 Views
Martin Hope
jobou
Asked: 2016-10-14 02:23:46 +0800 CST

nginx auth_request 如何返回后端状态码

  • 3

当使用的后端代理auth_request返回不同于 401 或 403 的错误代码时,nginx 将返回 500 错误代码。

ngx_http_auth_request_module 模块(1.5.4+)根据子请求的结果实现客户端授权。如果子请求返回 2xx 响应码,则允许访问。如果它返回 401 或 403,则访问被拒绝并带有相应的错误代码。子请求返回的任何其他响应代码都被视为错误。

有没有办法让 nginx 从后端返回状态码而不是 500 ?

nginx authorization
  • 1 个回答
  • 7425 Views
Martin Hope
suamikim
Asked: 2016-08-07 15:23:59 +0800 CST

MariaDb 的管理员密码似乎不起作用

  • 8

我刚刚安装MariaDb在一个新的 Ubuntu Gnome 上,然后运行​​mysql_secure_installation我设置了一个不错的管理员密码,删除了匿名用户等。

之后我意识到有关管理员密码的一些奇怪行为:

  • 如果我尝试使用命令从我的普通用户帐户登录,mysql -u root -p我总是会收到一个错误:ERROR 1698 (28000): Access denied for user 'root'@'localhost'
    我很确定我输入了我之前使用mysql_secure_installation设置的正确密码......
  • 当我使用 root 从 root 运行命令时sudo mysql -u root -p,无论我实际输入哪个密码,我总是可以访问数据库...

这是正常的行为,我做错了什么还是我搞砸了安装?

security mariadb authorization
  • 2 个回答
  • 10792 Views
Martin Hope
HSchmale
Asked: 2016-06-17 11:31:29 +0800 CST

在代理中传递授权基本标头

  • 5

我目前正在尝试获取反向/转发代理以将授权标头传递给目标服务器。我该怎么办?我已经查看了以下来源,其中一条评论指出这仅适用于 Proxy-Auth 标头。但是代理没有身份验证后端。它看起来像下面

用户 -> 代理(无 Auth Req)-> 后端(HTTP AUTH HERE)

https://stackoverflow.com/questions/6213028/setting-up-mod-proxy-to-pass-http-authentication-to-server

apache-2.2 reverse-proxy http-headers authorization
  • 1 个回答
  • 6958 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve